{"id":6239,"date":"2024-11-14T14:28:13","date_gmt":"2024-11-14T06:28:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6239\/"},"modified":"2024-11-14T14:28:13","modified_gmt":"2024-11-14T06:28:13","slug":"mysql%e5%a6%82%e4%bd%95%e5%b0%86%e6%89%80%e6%9c%89%e5%ad%97%e6%ae%b5%e6%9f%90%e7%ac%a6%e5%8f%b7%e5%89%8d%e6%95%b0%e6%8d%ae%e6%9b%bf%e6%8d%a2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6239\/","title":{"rendered":"mysql\u5982\u4f55\u5c06\u6240\u6709\u5b57\u6bb5\u67d0\u7b26\u53f7\u524d\u6570\u636e\u66ff\u6362"},"content":{"rendered":"<blockquote><p>\n  \u4f7f\u7528\u4ee5\u4e0b mysql \u8bed\u53e5\u5c06\u6240\u6709\u5b57\u6bb5\u4e2d\u7279\u5b9a\u7b26\u53f7\u524d\u7684\u6570\u636e\u66ff\u6362\uff1a&#8221;update table_name set field_name = replace(field_name, &#8216;old_value&#8217;, &#8216;new_value&#8217;)\u3002&#8221; \u5176\u4e2d\uff0ctable_name \u662f\u8868\u540d\uff0cfield_name \u662f\u5b57\u6bb5\u540d\uff0cold_value \u662f\u65e7\u503c\uff0cnew_value \u662f\u65b0\u503c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/15\/2024061515482633964.jpg\" class=\"aligncenter\" title=\"mysql\u5982\u4f55\u5c06\u6240\u6709\u5b57\u6bb5\u67d0\u7b26\u53f7\u524d\u6570\u636e\u66ff\u6362\u63d2\u56fe\" alt=\"mysql\u5982\u4f55\u5c06\u6240\u6709\u5b57\u6bb5\u67d0\u7b26\u53f7\u524d\u6570\u636e\u66ff\u6362\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u7528 MySQL \u5c06\u6240\u6709\u5b57\u6bb5\u4e2d\u7279\u5b9a\u7b26\u53f7\u524d\u7684\u6570\u636e\u66ff\u6362<\/strong><\/p>\n<p>\u8981\u5c06\u6240\u6709\u5b57\u6bb5\u4e2d\u7279\u5b9a\u7b26\u53f7\u524d\u7684\u6570\u636e\u66ff\u6362\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b MySQL \u8bed\u53e5\uff1a<\/p>\n<pre>UPDATE table_name\nSET field_name = REPLACE(field_name, 'old_value', 'new_value');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>table_name \u662f\u8981\u66f4\u65b0\u7684\u8868\u540d\u3002<\/li>\n<li>field_name \u662f\u8981\u66ff\u6362\u6570\u636e\u5b57\u6bb5\u7684\u540d\u79f0\u3002<\/li>\n<li>old_value \u662f\u8981\u66ff\u6362\u7684\u65e7\u503c\u3002<\/li>\n<li>new_value \u662f\u65b0\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a customers \u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2a\u540d\u4e3a name \u7684\u5b57\u6bb5\u3002\u8981\u5c06 name \u5b57\u6bb5\u4e2d\u6240\u6709\u4ee5\u8fde\u5b57\u7b26\uff08-\uff09\u5f00\u5934\u7684\u503c\u66ff\u6362\u4e3a\u4e0b\u5212\u7ebf (_)\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>UPDATE customers\nSET name = REPLACE(name, '-', '_');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u6b64\u8bed\u53e5\u5c06\u66ff\u6362\u6240\u6709\u5b57\u6bb5 name \u4e2d\u4ee5\u8fde\u5b57\u7b26\u5f00\u5934\u7684\u503c\uff0c\u5305\u62ec\u4e2d\u95f4\u6709\u8fde\u5b57\u7b26\u7684\u503c\u3002\u5982\u679c\u53ea\u60f3\u66ff\u6362\u5f00\u5934\u6709\u8fde\u5b57\u7b26\u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 REGEXP_REPLACE \u51fd\u6570\u3002<\/li>\n<li>\u8be5\u8bed\u53e5\u9002\u7528\u4e8e\u6240\u6709\u884c\u7684\u5b57\u6bb5 name\u3002\u5982\u679c\u60a8\u53ea\u60f3\u66f4\u65b0\u7279\u5b9a\u884c\u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 WHERE \u5b50\u53e5\u3002<\/li>\n<li>\u8bed\u53e5\u6267\u884c\u540e\uff0c\u6240\u6709\u53d7\u5f71\u54cd\u7684\u884c\u5c06\u66f4\u65b0\u4e3a\u65b0\u503c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5c06\u6240\u6709\u5b57\u6bb5\u67d0\u7b26\u53f7\u524d\u6570\u636e\u66ff\u6362\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>\u4f7f\u7528\u4ee5\u4e0b mysql \u8bed\u53e5\u5c06\u6240\u6709\u5b57\u6bb5\u4e2d\u7279\u5b9a\u7b26\u53f7\u524d\u7684\u6570\u636e\u66ff\u6362\uff1a&#8221;update table_name set field_name = replace(field_name, &#8216;old_value&#8217;, &#8216;new_value&#8217;)\u3002&#8221; \u5176\u4e2d\uff0ctable_name \u662f\u8868\u540d\uff0cfield_name \u662f\u5b57\u6bb5\u540d\uff0cold_value \u662f\u65e7\u503c\uff0cnew_value \u662f\u65b0\u503c\u3002 \u5982\u4f55\u7528 MySQL \u5c06\u6240\u6709\u5b57\u6bb5\u4e2d\u7279\u5b9a\u7b26\u53f7\u524d\u7684\u6570\u636e\u66ff\u6362 \u8981\u5c06\u6240\u6709\u5b57\u6bb5\u4e2d\u7279\u5b9a\u7b26\u53f7\u524d\u7684\u6570\u636e\u66ff\u6362\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b MySQL \u8bed\u53e5\uff1a UPDATE table_name SET field_name = REPLACE(field_name, &#8216;old_value&#8217;, &#8216;new_value&#8217;); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a table_name \u662f\u8981\u66f4\u65b0\u7684\u8868\u540d\u3002 field_name \u662f\u8981\u66ff\u6362\u6570\u636e\u5b57\u6bb5\u7684\u540d\u79f0\u3002 old_value \u662f\u8981\u66ff\u6362\u7684\u65e7\u503c\u3002 new_value \u662f\u65b0\u503c\u3002 \u793a\u4f8b\uff1a \u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a customers \u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e2a\u540d\u4e3a name \u7684\u5b57\u6bb5\u3002\u8981\u5c06 name \u5b57\u6bb5\u4e2d\u6240\u6709\u4ee5\u8fde\u5b57\u7b26\uff08-\uff09\u5f00\u5934\u7684\u503c\u66ff\u6362\u4e3a\u4e0b\u5212\u7ebf (_)\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a UPDATE customers SET name = REPLACE(name, &#8216;-&#8216;, [&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-6239","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6239","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=6239"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6239\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}