{"id":7000,"date":"2024-11-14T10:32:32","date_gmt":"2024-11-14T02:32:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7000\/"},"modified":"2024-11-14T10:32:32","modified_gmt":"2024-11-14T02:32:32","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:\/\/fwq.ai\/blog\/7000\/","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><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173026440576728.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 MySQL \u5220\u9664\u591a\u4e2a\u8868\u4e2d\u5305\u542b\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u6570\u636e\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 MySQL \u5220\u9664\u591a\u4e2a\u8868\u4e2d\u5305\u542b\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u6570\u636e\uff1f\u63d2\u56fe\" \/><\/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  \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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 MySQL \u5220\u9664\u591a\u4e2a\u8868\u4e2d\u5305\u542b\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u6570\u636e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5220\u9664\u591a\u4e2a\u8868\u4e2d\u5305\u542b\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u6570\u636e \u95ee\u9898\u63cf\u8ff0\uff1a \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 \u95ee\u9898\u89e3\u7b54\uff1a \u53ef\u4ee5\u4f7f\u7528 \u4e2d\u7684 delete \u8bed\u53e5\u7684\u591a\u8868\u8bed\u6cd5\u6765\u5b9e\u73b0\uff1a DELETE FROM t1, t2 USING t1 JOIN t2 ON t1.id = t2.id WHERE CONVERT(t1.username USING utf8mb4) = CONVERT(&#8216;coco&#8217; USING utf8mb4) OR CONVERT(t2.username USING utf8mb4) = CONVERT(&#8216;coco&#8217; USING utf8mb4); \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4\u5206\u89e3\uff1a delete from t1, t2\uff1a\u5220\u9664 t1 \u548c t2 \u4e24\u5f20\u8868\u4e2d\u7684\u6570\u636e\u3002 using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7000","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7000","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7000"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7000\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7000"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7000"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7000"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}