{"id":5153,"date":"2024-11-14T08:20:22","date_gmt":"2024-11-14T00:20:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5153\/"},"modified":"2024-11-14T08:20:22","modified_gmt":"2024-11-14T00:20:22","slug":"mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e5%ad%97%e7%ac%a6%e7%bc%96%e7%a0%81%e6%80%8e%e4%b9%88%e4%bf%ae%e6%94%b9","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5153\/","title":{"rendered":"mysql\u6570\u636e\u5e93\u7684\u5b57\u7b26\u7f16\u7801\u600e\u4e48\u4fee\u6539"},"content":{"rendered":"<blockquote><p>\n  mysql\u6570\u636e\u5e93\u5b57\u7b26\u7f16\u7801\u53ef\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u4fee\u6539\uff1a\u4fee\u6539\u6570\u636e\u5e93\u5b57\u7b26\u7f16\u7801\uff1aalter database database_name character set new_character_set;\u4fee\u6539\u8868\u5b57\u7b26\u7f16\u7801\uff1aalter table table_name convert to character set new_character_set;\u4fee\u6539\u5217\u5b57\u7b26\u7f16\u7801\uff1aalter table table_name modify column_name new_character_set;\u6307\u5b9a\u9ed8\u8ba4\u5b57\u7b26\u7f16\u7801\uff1a\u5728my.cn\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/22\/2024052217272621965.jpg\" class=\"aligncenter\" title=\"mysql\u6570\u636e\u5e93\u7684\u5b57\u7b26\u7f16\u7801\u600e\u4e48\u4fee\u6539\u63d2\u56fe\" alt=\"mysql\u6570\u636e\u5e93\u7684\u5b57\u7b26\u7f16\u7801\u600e\u4e48\u4fee\u6539\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u6570\u636e\u5e93\u5b57\u7b26\u7f16\u7801\u4fee\u6539\u65b9\u6cd5<\/strong><\/p>\n<p><strong>1. \u4fee\u6539\u6570\u636e\u5e93\u5b57\u7b26\u7f16\u7801<\/strong><\/p>\n<pre>ALTER DATABASE database_name CHARACTER SET new_character_set;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff1a\u5c06 test \u6570\u636e\u5e93\u5b57\u7b26\u7f16\u7801\u4fee\u6539\u4e3a utf8\uff1a<\/p>\n<pre>ALTER DATABASE test CHARACTER SET utf8;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4fee\u6539\u8868\u5b57\u7b26\u7f16\u7801<\/strong><\/p>\n<pre>ALTER TABLE table_name CONVERT TO CHARACTER SET new_character_set;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff1a\u5c06 users \u8868\u5b57\u7b26\u7f16\u7801\u4fee\u6539\u4e3a utf8mb4\uff1a<\/p>\n<pre>ALTER TABLE users CONVERT TO CHARACTER SET utf8mb4;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4fee\u6539\u5217\u5b57\u7b26\u7f16\u7801<\/strong><\/p>\n<pre>ALTER TABLE table_name MODIFY column_name new_character_set;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff1a\u5c06 users \u8868\u4e2d name \u5217\u5b57\u7b26\u7f16\u7801\u4fee\u6539\u4e3a utf8mb4\uff1a<\/p>\n<pre>ALTER TABLE users MODIFY name utf8mb4;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u6307\u5b9a\u9ed8\u8ba4\u5b57\u7b26\u7f16\u7801<\/strong><\/p>\n<p>\u4fee\u6539 MySQL \u914d\u7f6e\u6587\u4ef6 (my.cnf)\uff0c\u5728 [d] \u90e8\u5206\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>character-set-server=new_character_set<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff1a\u5c06 MySQL \u670d\u52a1\u5668\u9ed8\u8ba4\u5b57\u7b26\u7f16\u7801\u4fee\u6539\u4e3a utf8mb4\uff1a<\/p>\n<pre>[mysqld]\ncharacter-set-server=utf8mb4<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4fee\u6539\u540e\uff0c\u91cd\u542f MySQL \u670d\u52a1\u4ee5\u5e94\u7528\u66f4\u6539\u3002<\/p>\n<p><strong>5. \u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u4fee\u6539\u5b57\u7b26\u7f16\u7801**\u53ef\u80fd\u4f1a\u5bfc\u81f4\uff0c\u56e0\u6b64\u5728\u4fee\u6539\u4e4b\u524d\u8bf7\u521b\u5efa\u5907\u4efd\u3002<\/li>\n<li>\u4e0d\u540c\u7684\u5b57\u7b26\u96c6\u652f\u6301\u4e0d\u540c\u7684\u5b57\u7b26\u8303\u56f4\uff0c\u8bf7\u6839\u636e\u9700\u8981\u9009\u62e9\u5408\u9002\u7684\u5b57\u7b26\u96c6\u3002<\/li>\n<li>\u4e00\u65e6\u4fee\u6539\u4e86\u6570\u636e\u5e93\u7684\u5b57\u7b26\u7f16\u7801\uff0c\u5c31\u65e0\u6cd5\u6062\u590d\u5230\u4e4b\u524d\u7684\u5b57\u7b26\u7f16\u7801\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6570\u636e\u5e93\u7684\u5b57\u7b26\u7f16\u7801\u600e\u4e48\u4fee\u6539\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>mysql\u6570\u636e\u5e93\u5b57\u7b26\u7f16\u7801\u53ef\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u4fee\u6539\uff1a\u4fee\u6539\u6570\u636e\u5e93\u5b57\u7b26\u7f16\u7801\uff1aalter database database_name character set new_character_set;\u4fee\u6539\u8868\u5b57\u7b26\u7f16\u7801\uff1aalter table table_name convert to character set new_character_set;\u4fee\u6539\u5217\u5b57\u7b26\u7f16\u7801\uff1aalter table table_name modify column_name new_character_set;\u6307\u5b9a\u9ed8\u8ba4\u5b57\u7b26\u7f16\u7801\uff1a\u5728my.cn MySQL \u6570\u636e\u5e93\u5b57\u7b26\u7f16\u7801\u4fee\u6539\u65b9\u6cd5 1. \u4fee\u6539\u6570\u636e\u5e93\u5b57\u7b26\u7f16\u7801 ALTER DATABASE database_name CHARACTER SET new_character_set; \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff1a\u5c06 test \u6570\u636e\u5e93\u5b57\u7b26\u7f16\u7801\u4fee\u6539\u4e3a utf8\uff1a ALTER DATABASE test CHARACTER SET utf8; \u767b\u5f55\u540e\u590d\u5236 2. \u4fee\u6539\u8868\u5b57\u7b26\u7f16\u7801 ALTER TABLE table_name CONVERT TO CHARACTER SET new_character_set; \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff1a\u5c06 users \u8868\u5b57\u7b26\u7f16\u7801\u4fee\u6539\u4e3a utf8mb4\uff1a [&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-5153","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5153","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=5153"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5153\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}