{"id":6370,"date":"2024-11-14T14:08:14","date_gmt":"2024-11-14T06:08:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6370\/"},"modified":"2024-11-14T14:08:14","modified_gmt":"2024-11-14T06:08:14","slug":"mysql%e5%ad%97%e7%ac%a6%e9%9b%86%e4%b8%8d%e7%94%9f%e6%95%88%e6%80%8e%e4%b9%88%e5%8a%9e","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6370\/","title":{"rendered":"mysql\u5b57\u7b26\u96c6\u4e0d\u751f\u6548\u600e\u4e48\u529e"},"content":{"rendered":"<blockquote><p>\n  \u5bfc\u81f4 mysql \u5b57\u7b26\u96c6\u8bbe\u7f6e\u540e\u4e0d\u751f\u6548\u7684\u539f\u56e0\u53ef\u80fd\u6709\u591a\u79cd\uff1a\u5ba2\u6237\u7aef\u548c\u6570\u636e\u5e93\u5b57\u7b26\u96c6\u4e0d\u4e00\u81f4\u3002\u6570\u636e\u5e93\u5b57\u7b26\u96c6\u548c\u8868\u5b57\u7b26\u96c6\u4e0d\u4e00\u81f4\u3002\u5b57\u7b26\u96c6\u8f6c\u6362\u5f02\u5e38\u3002\u5176\u4ed6\u56e0\u7d20\uff08\u4f8b\u5982\u64cd\u4f5c\u7cfb\u7edf\u8bbe\u7f6e\u4e0d\u6b63\u786e\u3001collation \u672a\u6b63\u786e\u914d\u7f6e\u6216\u5b57\u7b26\u4e32\u6570\u636e\u4e2d\u5b58\u5728\u65e0\u6548\u5b57\u7b26\uff09\u3002\u89e3\u51b3\u6b65\u9aa4\uff1a\u68c0\u67e5\u5ba2\u6237\u7aef\u548c\u6570\u636e\u5e93\u5b57\u7b26\u96c6\u662f\u5426\u4e00\u81f4\u3002\u68c0\u67e5\u6570\u636e\u5e93\u548c\u8868\u5b57\u7b26\u96c6\u662f\u5426\u5339\u914d\u3002\u89e3\u51b3\u4efb\u4f55\u5b57\u7b26\u96c6\u8f6c\u6362\u5f02\u5e38\u3002\u68c0\u67e5\u5176\u4ed6\u6f5c\u5728\u56e0\u7d20\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/01\/2024080103124231804.jpg\" class=\"aligncenter\" title=\"mysql\u5b57\u7b26\u96c6\u4e0d\u751f\u6548\u600e\u4e48\u529e\u63d2\u56fe\" alt=\"mysql\u5b57\u7b26\u96c6\u4e0d\u751f\u6548\u600e\u4e48\u529e\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u5b57\u7b26\u96c6\u4e0d\u751f\u6548\u7684\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong>\u4e3a\u4ec0\u4e48 MySQL \u5b57\u7b26\u96c6\u8bbe\u7f6e\u540e\u4e0d\u751f\u6548\uff1f<\/p>\n<p><strong>\u7b54\u6848\uff1a<\/strong>\u5bfc\u81f4 MySQL \u5b57\u7b26\u96c6\u8bbe\u7f6e\u540e\u4e0d\u751f\u6548\u7684\u539f\u56e0\u53ef\u80fd\u6709\u591a\u79cd\uff0c\u5305\u62ec\uff1a<\/p>\n<p><strong>1. \u5ba2\u6237\u7aef\u548c\u6570\u636e\u5e93\u5b57\u7b26\u96c6\u4e0d\u4e00\u81f4<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u5ba2\u6237\u7aef\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u7684\u5b57\u7b26\u96c6\u4e0e MySQL \u6570\u636e\u5e93\u7684\u5b57\u7b26\u96c6\u76f8\u540c\u3002<\/li>\n<li>\u5728\u5ba2\u6237\u7aef\u8fde\u63a5\u65f6\uff0c\u4f7f\u7528 SET NAMES \u8bed\u53e5\u663e\u5f0f\u8bbe\u7f6e\u5b57\u7b26\u96c6\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<pre>SET NAMES utf8;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u6570\u636e\u5e93\u5b57\u7b26\u96c6\u548c\u8868\u5b57\u7b26\u96c6\u4e0d\u4e00\u81f4<\/strong><\/p>\n<ul>\n<li>\u9a8c\u8bc1\u6570\u636e\u5e93\u7684\u9ed8\u8ba4\u5b57\u7b26\u96c6\uff08\u901a\u8fc7\u67e5\u8be2 SHOW VARIABLES LIKE &#8216;%character_set%&#8217;;\uff09\u4e0e\u8be5\u8868\u7684\u5b57\u7b26\u96c6\uff08\u901a\u8fc7\u67e5\u8be2 SHOW CREATE TABLE <\/li>\n<li>\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u4fee\u6539\u8868\u7684\u5b57\u7b26\u96c6\uff0c\u4f8b\u5982\uff1a<\/li>\n<pre>ALTER TABLE &lt;table&gt; CONVERT TO CHARACTER SET utf8;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u5b57\u7b26\u96c6\u8f6c\u6362\u5f02\u5e38<\/strong><\/p>\n<ul>\n<li>\u67d0\u4e9b\u5b57\u7b26\u96c6\u4e4b\u95f4\u7684\u8f6c\u6362\u53ef\u80fd\u5bfc\u81f4\u6216\u4e0d\u6b63\u786e\u663e\u793a\u3002<\/li>\n<li>\u8003\u8651\u4f7f\u7528\u517c\u5bb9\u7684\u5b57\u7b26\u96c6\uff0c\u6216\u4f7f\u7528 CAST() \u51fd\u6570\u8fdb\u884c\u663e\u5f0f\u8f6c\u6362\u3002<\/li>\n<\/ul>\n<p><strong>4. \u5176\u4ed6\u56e0\u7d20<\/strong><\/p>\n<ul>\n<li>\u64cd\u4f5c\u7cfb\u7edf\u8bbe\u7f6e\u4e0d\u6b63\u786e<\/li>\n<li>collation \u672a\u6b63\u786e\u914d\u7f6e<\/li>\n<li>\u5b57\u7b26\u4e32\u6570\u636e\u4e2d\u5b58\u5728\u65e0\u6548\u5b57\u7b26<\/li>\n<\/ul>\n<p><strong>\u89e3\u51b3\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li>\u68c0\u67e5\u5ba2\u6237\u7aef\u548c\u6570\u636e\u5e93\u5b57\u7b26\u96c6\u662f\u5426\u4e00\u81f4\u3002<\/li>\n<li>\u68c0\u67e5\u6570\u636e\u5e93\u548c\u8868\u5b57\u7b26\u96c6\u662f\u5426\u5339\u914d\u3002<\/li>\n<li>\u89e3\u51b3\u4efb\u4f55\u5b57\u7b26\u96c6\u8f6c\u6362\u5f02\u5e38\u3002<\/li>\n<li>\u68c0\u67e5\u5176\u4ed6\u6f5c\u5728\u56e0\u7d20\u3002<\/li>\n<\/ol>\n<p>\u901a\u8fc7\u9075\u5faa\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u60a8\u53ef\u4ee5\u8bca\u65ad\u5e76\u89e3\u51b3 MySQL \u5b57\u7b26\u96c6\u4e0d\u751f\u6548\u7684\u95ee\u9898\uff0c\u786e\u4fdd\u6570\u636e\u6b63\u786e\u5b58\u50a8\u548c\u663e\u793a\u3002<\/p>\n<table>\n   ;\uff09\u662f\u5426\u5339\u914d\u3002<br \/>\n <\/table>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5b57\u7b26\u96c6\u4e0d\u751f\u6548\u600e\u4e48\u529e\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>\u5bfc\u81f4 mysql \u5b57\u7b26\u96c6\u8bbe\u7f6e\u540e\u4e0d\u751f\u6548\u7684\u539f\u56e0\u53ef\u80fd\u6709\u591a\u79cd\uff1a\u5ba2\u6237\u7aef\u548c\u6570\u636e\u5e93\u5b57\u7b26\u96c6\u4e0d\u4e00\u81f4\u3002\u6570\u636e\u5e93\u5b57\u7b26\u96c6\u548c\u8868\u5b57\u7b26\u96c6\u4e0d\u4e00\u81f4\u3002\u5b57\u7b26\u96c6\u8f6c\u6362\u5f02\u5e38\u3002\u5176\u4ed6\u56e0\u7d20\uff08\u4f8b\u5982\u64cd\u4f5c\u7cfb\u7edf\u8bbe\u7f6e\u4e0d\u6b63\u786e\u3001collation \u672a\u6b63\u786e\u914d\u7f6e\u6216\u5b57\u7b26\u4e32\u6570\u636e\u4e2d\u5b58\u5728\u65e0\u6548\u5b57\u7b26\uff09\u3002\u89e3\u51b3\u6b65\u9aa4\uff1a\u68c0\u67e5\u5ba2\u6237\u7aef\u548c\u6570\u636e\u5e93\u5b57\u7b26\u96c6\u662f\u5426\u4e00\u81f4\u3002\u68c0\u67e5\u6570\u636e\u5e93\u548c\u8868\u5b57\u7b26\u96c6\u662f\u5426\u5339\u914d\u3002\u89e3\u51b3\u4efb\u4f55\u5b57\u7b26\u96c6\u8f6c\u6362\u5f02\u5e38\u3002\u68c0\u67e5\u5176\u4ed6\u6f5c\u5728\u56e0\u7d20\u3002 MySQL \u5b57\u7b26\u96c6\u4e0d\u751f\u6548\u7684\u89e3\u51b3\u65b9\u6848 \u95ee\u9898\uff1a\u4e3a\u4ec0\u4e48 MySQL \u5b57\u7b26\u96c6\u8bbe\u7f6e\u540e\u4e0d\u751f\u6548\uff1f \u7b54\u6848\uff1a\u5bfc\u81f4 MySQL \u5b57\u7b26\u96c6\u8bbe\u7f6e\u540e\u4e0d\u751f\u6548\u7684\u539f\u56e0\u53ef\u80fd\u6709\u591a\u79cd\uff0c\u5305\u62ec\uff1a 1. \u5ba2\u6237\u7aef\u548c\u6570\u636e\u5e93\u5b57\u7b26\u96c6\u4e0d\u4e00\u81f4 \u786e\u4fdd\u5ba2\u6237\u7aef\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u7684\u5b57\u7b26\u96c6\u4e0e MySQL \u6570\u636e\u5e93\u7684\u5b57\u7b26\u96c6\u76f8\u540c\u3002 \u5728\u5ba2\u6237\u7aef\u8fde\u63a5\u65f6\uff0c\u4f7f\u7528 SET NAMES \u8bed\u53e5\u663e\u5f0f\u8bbe\u7f6e\u5b57\u7b26\u96c6\uff0c\u4f8b\u5982\uff1a SET NAMES utf8; \u767b\u5f55\u540e\u590d\u5236 2. \u6570\u636e\u5e93\u5b57\u7b26\u96c6\u548c\u8868\u5b57\u7b26\u96c6\u4e0d\u4e00\u81f4 \u9a8c\u8bc1\u6570\u636e\u5e93\u7684\u9ed8\u8ba4\u5b57\u7b26\u96c6\uff08\u901a\u8fc7\u67e5\u8be2 SHOW VARIABLES LIKE &#8216;%character_set%&#8217;;\uff09\u4e0e\u8be5\u8868\u7684\u5b57\u7b26\u96c6\uff08\u901a\u8fc7\u67e5\u8be2 SHOW CREATE TABLE \u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u4fee\u6539\u8868\u7684\u5b57\u7b26\u96c6\uff0c\u4f8b\u5982\uff1a ALTER TABLE &lt;table&gt; CONVERT TO CHARACTER SET utf8; \u767b\u5f55\u540e\u590d\u5236 3. \u5b57\u7b26\u96c6\u8f6c\u6362\u5f02\u5e38 \u67d0\u4e9b\u5b57\u7b26\u96c6\u4e4b\u95f4\u7684\u8f6c\u6362\u53ef\u80fd\u5bfc\u81f4\u6216\u4e0d\u6b63\u786e\u663e\u793a\u3002 \u8003\u8651\u4f7f\u7528\u517c\u5bb9\u7684\u5b57\u7b26\u96c6\uff0c\u6216\u4f7f\u7528 CAST() \u51fd\u6570\u8fdb\u884c\u663e\u5f0f\u8f6c\u6362\u3002 4. [&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-6370","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6370","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=6370"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6370\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}