{"id":44856,"date":"2024-12-01T13:34:52","date_gmt":"2024-12-01T05:34:52","guid":{"rendered":"https:\/\/fwq.ai\/blog\/44856\/"},"modified":"2024-12-01T13:34:52","modified_gmt":"2024-12-01T05:34:52","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-sql-%e8%af%ad%e5%8f%a5%e5%88%a0%e9%99%a4%e5%8c%85%e5%90%ab%e7%89%b9%e5%ae%9a%e5%ad%97%e7%ac%a6%e7%9a%84%e8%b7%a8%e8%a1%a8%e6%95%b0%e6%8d%ae%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/44856\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f<\/h1>\n<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300a\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241103\/17306078886726fb106691d.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u7528sql\u8bed\u53e5\u5220\u9664\u591a\u8868\u4e2d\u7684\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u6570\u636e<\/strong><\/p>\n<p>\u5df2\u77e5\u6709\u4e24\u5f20\u8868t1\u548ct2\uff0c\u8868t1\u7684\u5b57\u6bb5\u4e3aid\u548cusername\uff0c\u8868t2\u7684\u5b57\u6bb5\u4e3aid\u548cusername\uff0c\u7f16\u7801\u4e3agbk\u3002\u8868t1\u4e2d\u5305\u542b\u4ee5\u4e0b\u6570\u636e\uff1a<\/p>\n<pre>\u6570\u636e1: 1 c\u01d2c\u01d2\n\u6570\u636e2: 2 coco<\/pre>\n<p>\u8868t2\u4e2d\u5305\u542b\u4ee5\u4e0b\u6570\u636e\uff1a<\/p>\n<pre>\u6570\u636e1: 1 c\u00f3c\u01d2<\/pre>\n<p>\u60a8\u9700\u8981\u4f7f\u7528utf8mb4\u6821\u5bf9\u96c6\u5220\u9664\u8fd9\u4e24\u4e2a\u8868\u4e2d\u6240\u6709\u5305\u542b&#8221;coco&#8221;\u5b57\u7b26\u7684\u6570\u636e\u3002\u9488\u5bf9\u5355\u8868\u7684\u5220\u9664\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>delete from t1 where convert(username using utf8mb4) = convert(username using utf8mb4);<\/pre>\n<p>\u5bf9\u4e8e\u591a\u8868\u7684\u5220\u9664\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>delete [low_priority] [quick] [ignore]\nfrom table_references\n[where where_condition]<\/pre>\n<p>\u5176\u4e2d\uff0ctable_references\u6307\u5b9a\u8981\u5220\u9664\u6570\u636e\u7684\u8868\uff0cwhere_condition\u6307\u5b9a\u5220\u9664\u7684\u6761\u4ef6\u3002\u5728\u672c\u4f8b\u4e2d\uff0cwhere\u6761\u4ef6\u4e3ausername\u5305\u542bcoco\u5b57\u7b26\uff0c\u4f7f\u7528utf8mb4\u6821\u5bf9\u96c6\u8fdb\u884c\u6bd4\u8f83\u3002\u56e0\u6b64\uff0c\u6700\u7ec8\u7684\u591a\u8868\u5220\u9664\u8bed\u53e5\u4e3a\uff1a<\/p>\n<pre>DELETE\nFROM t1, t2\nWHERE convert(username USING utf8mb4) LIKE '%coco%'<\/pre>\n<p>\u6267\u884c\u6b64\u8bed\u53e5\u540e\uff0ct1\u548ct2\u8868\u4e2d\u5305\u542bcoco\u5b57\u7b26\u7684\u6240\u6709\u6570\u636e\u5c06\u88ab\u5220\u9664\u3002<\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f \u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300a\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002 \u7528sql\u8bed\u53e5\u5220\u9664\u591a\u8868\u4e2d\u7684\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u6570\u636e \u5df2\u77e5\u6709\u4e24\u5f20\u8868t1\u548ct2\uff0c\u8868t1\u7684\u5b57\u6bb5\u4e3aid\u548cusername\uff0c\u8868t2\u7684\u5b57\u6bb5\u4e3aid\u548cusername\uff0c\u7f16\u7801\u4e3agbk\u3002\u8868t1\u4e2d\u5305\u542b\u4ee5\u4e0b\u6570\u636e\uff1a \u6570\u636e1: 1 c\u01d2c\u01d2 \u6570\u636e2: 2 coco \u8868t2\u4e2d\u5305\u542b\u4ee5\u4e0b\u6570\u636e\uff1a \u6570\u636e1: 1 c\u00f3c\u01d2 \u60a8\u9700\u8981\u4f7f\u7528utf8mb4\u6821\u5bf9\u96c6\u5220\u9664\u8fd9\u4e24\u4e2a\u8868\u4e2d\u6240\u6709\u5305\u542b&#8221;coco&#8221;\u5b57\u7b26\u7684\u6570\u636e\u3002\u9488\u5bf9\u5355\u8868\u7684\u5220\u9664\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a delete from t1 where convert(username using utf8mb4) = convert(username using utf8mb4); \u5bf9\u4e8e\u591a\u8868\u7684\u5220\u9664\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a delete [low_priority] [quick] [ignore] from table_references [where where_condition] \u5176\u4e2d\uff0ctable_references\u6307\u5b9a\u8981\u5220\u9664\u6570\u636e\u7684\u8868\uff0cwhere_condition\u6307\u5b9a\u5220\u9664\u7684\u6761\u4ef6\u3002\u5728\u672c\u4f8b\u4e2d\uff0cwhere\u6761\u4ef6\u4e3ausername\u5305\u542bcoco\u5b57\u7b26\uff0c\u4f7f\u7528utf8mb4\u6821\u5bf9\u96c6\u8fdb\u884c\u6bd4\u8f83\u3002\u56e0\u6b64\uff0c\u6700\u7ec8\u7684\u591a\u8868\u5220\u9664\u8bed\u53e5\u4e3a\uff1a DELETE FROM t1, t2 WHERE convert(username USING utf8mb4) LIKE &#8216;%coco%&#8217; \u6267\u884c\u6b64\u8bed\u53e5\u540e\uff0ct1\u548ct2\u8868\u4e2d\u5305\u542bcoco\u5b57\u7b26\u7684\u6240\u6709\u6570\u636e\u5c06\u88ab\u5220\u9664\u3002 \u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/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-44856","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/44856","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=44856"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/44856\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=44856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=44856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=44856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}