{"id":6244,"date":"2024-11-14T10:44:34","date_gmt":"2024-11-14T02:44:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6244\/"},"modified":"2024-11-14T10:44:34","modified_gmt":"2024-11-14T02:44:34","slug":"mysql%e5%a6%82%e4%bd%95%e6%9f%a5%e8%af%a2%e5%8c%85%e5%90%ab%e6%9f%90%e4%b8%aa%e5%ad%97%e6%ae%b5%e7%9a%84%e8%ae%b0%e5%bd%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6244\/","title":{"rendered":"mysql\u5982\u4f55\u67e5\u8be2\u5305\u542b\u67d0\u4e2a\u5b57\u6bb5\u7684\u8bb0\u5f55"},"content":{"rendered":"<blockquote><p>\n  \u8981\u67e5\u8be2 mysql \u4e2d\u5305\u542b\u67d0\u4e2a\u5b57\u6bb5\u7684\u8bb0\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528 like \u8fd0\u7b97\u7b26\u5339\u914d\u6a21\u5f0f\uff0c\u5177\u4f53\u4f7f\u7528\u65b9\u5f0f\u4e3a\uff1a\u6307\u5b9a\u8868\u540d\uff1aselect * from table_name\u5b9a\u4e49\u641c\u7d22\u6761\u4ef6\uff1awhere column_name like &#8216;pattern&#8217;\u8bbe\u7f6e\u901a\u914d\u7b26\uff1a% \u8868\u793a\u4efb\u610f\u6570\u91cf\u5b57\u7b26\uff08\u4f8b\u5982\uff1aname like &#8216;john%&#8217;)\u6392\u9664\u7279\u5b9a\u5b57\u7b26\u4e32\uff1anot like &#8216;%john%&#8217;\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/15\/2024061516122531450.jpg\" class=\"aligncenter\" title=\"mysql\u5982\u4f55\u67e5\u8be2\u5305\u542b\u67d0\u4e2a\u5b57\u6bb5\u7684\u8bb0\u5f55\u63d2\u56fe\" alt=\"mysql\u5982\u4f55\u67e5\u8be2\u5305\u542b\u67d0\u4e2a\u5b57\u6bb5\u7684\u8bb0\u5f55\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u67e5\u8be2\u5305\u542b\u67d0\u4e2a\u5b57\u6bb5\u7684 MySQL \u8bb0\u5f55<\/strong><\/p>\n<p>\u5728 MySQL \u4e2d\u67e5\u8be2\u5305\u542b\u67d0\u4e2a\u5b57\u6bb5\u7684\u8bb0\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528 LIKE \u8fd0\u7b97\u7b26\u3002LIKE \u8fd0\u7b97\u7b26\u7528\u4e8e\u67e5\u627e\u4e0e\u6307\u5b9a\u6a21\u5f0f\u5339\u914d\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>SELECT * FROM table_name WHERE column_name LIKE 'pattern';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5176\u4e2d\uff1a<\/strong><\/p>\n<ul>\n<li>table_name \u662f\u8981\u67e5\u8be2\u7684\u8868\u540d\u3002<\/li>\n<li>column_name \u662f\u8981\u641c\u7d22\u7684\u5217\u540d\u3002<\/li>\n<li>pattern \u662f\u8981\u5339\u914d\u7684\u6a21\u5f0f\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u67e5\u8be2\u67e5\u627e\u5305\u542b &#8220;name&#8221; \u5b57\u6bb5\u4e14\u5176\u503c\u4e3a &#8220;John%&#8221; \u7684 customers \u8868\u4e2d\u7684\u8bb0\u5f55\uff1a<\/p>\n<pre>SELECT * FROM customers WHERE name LIKE 'John%';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>% \u662f\u901a\u914d\u7b26\uff0c\u8868\u793a\u4efb\u4f55\u6570\u91cf\u7684\u5b57\u7b26\u3002<\/li>\n<li>\u5982\u679c\u8981\u67e5\u627e\u786e\u5207\u5339\u914d\u7684\u5b57\u7b26\u4e32\uff0c\u53ef\u4ee5\u4f7f\u7528 = \u8fd0\u7b97\u7b26\u3002<\/li>\n<li>LIKE \u8fd0\u7b97\u7b26\u8fd8\u53ef\u4ee5\u7528\u4e8e\u67e5\u627e\u4e0d\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8bb0\u5f55\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u67e5\u8be2\u67e5\u627e\u4e0d\u5305\u542b &#8220;John&#8221; \u7684 customers \u8868\u4e2d\u7684\u8bb0\u5f55\uff1a<\/li>\n<\/ul>\n<pre>SELECT * FROM customers WHERE name NOT LIKE '%John%';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5176\u4ed6\u9009\u9879\uff1a<\/strong><\/p>\n<p>\u9664\u4e86 LIKE \u8fd0\u7b97\u7b26\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u9009\u9879\u6765\u67e5\u8be2\u5305\u542b\u67d0\u4e2a\u5b57\u6bb5\u7684\u8bb0\u5f55\uff1a<\/p>\n<ul>\n<li> <strong>REGEXP \u8fd0\u7b97\u7b26\uff1a<\/strong>\u7528\u4e8e\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u5b57\u7b26\u4e32\u3002<\/li>\n<li> <strong>SOUNDEX \u51fd\u6570\uff1a<\/strong>\u7528\u4e8e\u6839\u636e\u97f3\u6807\u5339\u914d\u5b57\u7b26\u4e32\u3002<\/li>\n<li> <strong>\u5168\u6587\u641c\u7d22\uff1a<\/strong>\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u5168\u6587\u7d22\u5f15\u5e76\u5728\u5176\u4e0a\u8fdb\u884c\u641c\u7d22\u6765\u5b9e\u73b0\u5bf9\u5927\u91cf\u6587\u672c\u6570\u636e\u7684\u5feb\u901f\u641c\u7d22\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u67e5\u8be2\u5305\u542b\u67d0\u4e2a\u5b57\u6bb5\u7684\u8bb0\u5f55\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>\u8981\u67e5\u8be2 mysql \u4e2d\u5305\u542b\u67d0\u4e2a\u5b57\u6bb5\u7684\u8bb0\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528 like \u8fd0\u7b97\u7b26\u5339\u914d\u6a21\u5f0f\uff0c\u5177\u4f53\u4f7f\u7528\u65b9\u5f0f\u4e3a\uff1a\u6307\u5b9a\u8868\u540d\uff1aselect * from table_name\u5b9a\u4e49\u641c\u7d22\u6761\u4ef6\uff1awhere column_name like &#8216;pattern&#8217;\u8bbe\u7f6e\u901a\u914d\u7b26\uff1a% \u8868\u793a\u4efb\u610f\u6570\u91cf\u5b57\u7b26\uff08\u4f8b\u5982\uff1aname like &#8216;john%&#8217;)\u6392\u9664\u7279\u5b9a\u5b57\u7b26\u4e32\uff1anot like &#8216;%john%&#8217; \u5982\u4f55\u67e5\u8be2\u5305\u542b\u67d0\u4e2a\u5b57\u6bb5\u7684 MySQL \u8bb0\u5f55 \u5728 MySQL \u4e2d\u67e5\u8be2\u5305\u542b\u67d0\u4e2a\u5b57\u6bb5\u7684\u8bb0\u5f55\uff0c\u53ef\u4ee5\u4f7f\u7528 LIKE \u8fd0\u7b97\u7b26\u3002LIKE \u8fd0\u7b97\u7b26\u7528\u4e8e\u67e5\u627e\u4e0e\u6307\u5b9a\u6a21\u5f0f\u5339\u914d\u7684\u5b57\u7b26\u4e32\u3002 \u8bed\u6cd5\uff1a SELECT * FROM table_name WHERE column_name LIKE &#8216;pattern&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a table_name \u662f\u8981\u67e5\u8be2\u7684\u8868\u540d\u3002 column_name \u662f\u8981\u641c\u7d22\u7684\u5217\u540d\u3002 pattern \u662f\u8981\u5339\u914d\u7684\u6a21\u5f0f\u3002 \u793a\u4f8b\uff1a \u4ee5\u4e0b\u67e5\u8be2\u67e5\u627e\u5305\u542b &#8220;name&#8221; \u5b57\u6bb5\u4e14\u5176\u503c\u4e3a &#8220;John%&#8221; \u7684 customers \u8868\u4e2d\u7684\u8bb0\u5f55\uff1a SELECT * FROM customers WHERE [&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-6244","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6244","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=6244"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6244\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}