{"id":201058,"date":"2025-05-06T11:22:27","date_gmt":"2025-05-06T03:22:27","guid":{"rendered":"https:\/\/server.hk\/cnblog\/201058\/"},"modified":"2025-05-06T11:22:27","modified_gmt":"2025-05-06T03:22:27","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-mysql-%e5%88%a0%e9%99%a4%e5%a4%9a%e4%b8%aa%e8%a1%a8%e4%b8%ad%e5%8c%85%e5%90%ab%e6%8c%87%e5%ae%9a%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%9a%84%e6%95%b0%e6%8d%ae%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/201058\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 MySQL \u5220\u9664\u591a\u4e2a\u8868\u4e2d\u5305\u542b\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u6570\u636e\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 MySQL \u5220\u9664\u591a\u4e2a\u8868\u4e2d\u5305\u542b\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u6570\u636e\uff1f<\/h1>\n<p>\u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\u4e3b\u673a\u5b9d\u8d1d\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241128\/17327972136748631d33f26.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u5220\u9664\u591a\u4e2a\u8868\u4e2d\u5305\u542b\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u6570\u636e<\/strong><\/p>\n<p><strong>\u95ee\u9898\u63cf\u8ff0\uff1a<\/strong><\/p>\n<p>\u8868 t1 \u548c t2 \u4e2d\u5b58\u50a8\u4e86\u6c49\u5b57\u6570\u636e\uff0c\u4f7f\u7528 gbk \u7f16\u7801\u3002\u73b0\u5728\u9700\u8981\u5220\u9664\u4e24\u5f20\u8868\u4e2d\u6240\u6709\u5305\u542b\u201ccoco\u201d\u5b57\u7b26\u4e32\u7684\u6570\u636e\uff0c\u4f46\u9700\u8981\u4f7f\u7528 utf8mb4 \u6821\u5bf9\u96c6\u8fdb\u884c\u5bf9\u6bd4\u3002<\/p>\n<p><strong>\u95ee\u9898\u89e3\u7b54\uff1a<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 mysql \u4e2d\u7684 delete \u8bed\u53e5\u7684\u591a\u8868\u8bed\u6cd5\u6765\u5b9e\u73b0\uff1a<\/p>\n<pre>DELETE FROM t1, t2\nUSING t1\nJOIN t2 ON t1.id = t2.id\nWHERE CONVERT(t1.username USING utf8mb4) = CONVERT('coco' USING utf8mb4)\n  OR CONVERT(t2.username USING utf8mb4) = CONVERT('coco' USING utf8mb4);<\/pre>\n<p><strong>\u6b65\u9aa4\u5206\u89e3\uff1a<\/strong><\/p>\n<ol>\n<li>delete from t1, t2\uff1a\u5220\u9664 t1 \u548c t2 \u4e24\u5f20\u8868\u4e2d\u7684\u6570\u636e\u3002<\/li>\n<li>using t1\uff1a\u6307\u5b9a t1 \u8868\u4e3a delete \u8bed\u53e5\u7684\u57fa\u7840\u8868\u3002<\/li>\n<li>join t2 on t1.id = t2.id\uff1a\u8fde\u63a5 t1 \u548c t2 \u8868\uff0c\u57fa\u4e8e id \u5217\u3002<\/li>\n<li>where \u5b50\u53e5\uff1a\u4f7f\u7528 convert \u51fd\u6570\u5c06\u8868\u4e2d\u5b58\u50a8\u7684 gbk \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a utf8mb4 \u7f16\u7801\uff0c\u5e76\u4e0e &#8216;coco&#8217; \u5b57\u7b26\u4e32\u8fdb\u884c\u6bd4\u8f83\u3002\u53ea\u6709\u5f53\u4e24\u4e2a\u5b57\u7b26\u4e32\u5728 utf8mb4 \u6821\u5bf9\u96c6\u4e2d\u7684\u8f6c\u6362\u7ed3\u679c\u76f8\u7b49\u65f6\uff0c\u624d\u4f1a\u5220\u9664\u76f8\u5e94\u7684\u6570\u636e\u3002<\/li>\n<\/ol>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528 MySQL \u5220\u9664\u591a\u4e2a\u8868\u4e2d\u5305\u542b\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u6570\u636e\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6570\u636e\u5e93\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 MySQL \u5220\u9664\u591a\u4e2a\u8868&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-201058","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201058","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=201058"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/201058\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=201058"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=201058"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=201058"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}