{"id":5553,"date":"2024-11-14T12:49:12","date_gmt":"2024-11-14T04:49:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5553\/"},"modified":"2024-11-14T12:49:12","modified_gmt":"2024-11-14T04:49:12","slug":"mysql%e8%af%ad%e8%a8%80%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%ae%e4%b8%ad%e6%96%87","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5553\/","title":{"rendered":"mysql\u8bed\u8a00\u600e\u4e48\u8bbe\u7f6e\u4e2d\u6587"},"content":{"rendered":"<blockquote><p>\n  \u5728 mysql \u4e2d\u8bbe\u7f6e\u4e2d\u6587\u7684\u65b9\u6cd5\u4e3a\uff1a\u4fee\u6539 my.cnf \u6587\u4ef6\uff0c\u8bbe\u7f6e character-set-server \u548c collation-server \u4e3a utf8mb4 \u548c utf8mb4_unicode_ci\u3002\u4fee\u6539\u6570\u636e\u5e93\u548c\u8868\uff0c\u4f7f\u5176\u5b57\u7b26\u96c6\u548c\u6821\u5bf9\u89c4\u5219\u4e3a utf8mb4 \u548c utf8mb4_unicode_ci\u3002\u91cd\u542f mysql \u670d\u52a1\uff0c\u5373\u53ef\u751f\u6548\u3002\u9a8c\u8bc1\u8bbe\u7f6e\uff0c\u786e\u8ba4\u5b57\u7b26\u96c6\u548c\u6821\u5bf9\u89c4\u5219\u5df2\u66f4\u65b0\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/29\/2024052909392511858.jpg\" class=\"aligncenter\" title=\"mysql\u8bed\u8a00\u600e\u4e48\u8bbe\u7f6e\u4e2d\u6587\u63d2\u56fe\" alt=\"mysql\u8bed\u8a00\u600e\u4e48\u8bbe\u7f6e\u4e2d\u6587\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u4e2d\u8bbe\u7f6e\u4e2d\u6587\u7684\u65b9\u6cd5<\/strong><\/p>\n<p><strong>\u4e00\u3001\u914d\u7f6e my.cnf \u6587\u4ef6<\/strong><\/p>\n<ol>\n<li>\n<p>\u6253\u5f00 MySQL \u914d\u7f6e\u6587\u4ef6 my.cnf\u3002\u8be5\u6587\u4ef6\u901a\u5e38\u4f4d\u4e8e\u4ee5\u4e0b\u4f4d\u7f6e\uff1a<\/p>\n<ul>\n<li>Windows\uff1aC:ProgramDataMySQLMySQL Server 8.0my.ini<\/li>\n<li>Linux\/macOS\uff1a\/etc\/\/my.cnf<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6dfb\u52a0\u6216\u7f16\u8f91\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre>[mysqld]\ncharacter-set-server=utf8mb4\ncollation-server=utf8mb4_unicode_ci<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p><strong>\u4e8c\u3001\u66f4\u65b0\u6570\u636e\u5e93\u548c\u8868<\/strong><\/p>\n<ol>\n<li>\n<p>\u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93\uff1a<\/p>\n<pre>mysql -u root -p<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u66f4\u65b0\u6570\u636e\u5e93\u7684\u9ed8\u8ba4\u5b57\u7b26\u96c6\u548c\u6821\u5bf9\u89c4\u5219\uff1a<\/p>\n<pre>ALTER DATABASE database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u66f4\u65b0\u8868\uff1a<\/p>\n<pre>ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p><strong>\u4e09\u3001\u91cd\u542f MySQL \u670d\u52a1<\/strong><\/p>\n<ol>\n<li>\n<p>\u505c\u6b62 MySQL \u670d\u52a1\uff1a<\/p>\n<pre>service mysql stop<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u91cd\u65b0\u542f\u52a8 MySQL \u670d\u52a1\uff1a<\/p>\n<pre>service mysql start<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p><strong>\u56db\u3001\u9a8c\u8bc1\u8bbe\u7f6e<\/strong><\/p>\n<ol>\n<li>\n<p>\u91cd\u65b0\u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93\uff1a<\/p>\n<pre>mysql -u root -p<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u5f53\u524d\u5b57\u7b26\u96c6\u548c\u6821\u5bf9\u89c4\u5219\uff1a<\/p>\n<pre>SHOW VARIABLES LIKE 'character_set%';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>utf8mb4 \u662f\u517c\u5bb9 UTF-8 \u7f16\u7801\u7684\u5b57\u7b26\u96c6\uff0c\u5efa\u8bae\u4f7f\u7528\u3002<\/li>\n<li>utf8mb4_unicode_ci \u662f\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u3001\u4e0d\u533a\u5206\u91cd\u97f3\u7684\u6821\u5bf9\u89c4\u5219\u3002<\/li>\n<li>\u66f4\u6539\u5b57\u7b26\u96c6\u548c\u6821\u5bf9\u89c4\u5219\u53ef\u80fd\u9700\u8981\u4e00\u4e9b\u65f6\u95f4\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u6570\u636e\u5e93\u548c\u8868\u7684\u5927\u5c0f\u3002<\/li>\n<li>\u5728\u66f4\u6539\u5b57\u7b26\u96c6\u548c\u6821\u5bf9\u89c4\u5219\u4e4b\u524d\uff0c\u8bf7\u5148\u5907\u4efd\u6570\u636e\u5e93\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8bed\u8a00\u600e\u4e48\u8bbe\u7f6e\u4e2d\u6587\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>\u5728 mysql \u4e2d\u8bbe\u7f6e\u4e2d\u6587\u7684\u65b9\u6cd5\u4e3a\uff1a\u4fee\u6539 my.cnf \u6587\u4ef6\uff0c\u8bbe\u7f6e character-set-server \u548c collation-server \u4e3a utf8mb4 \u548c utf8mb4_unicode_ci\u3002\u4fee\u6539\u6570\u636e\u5e93\u548c\u8868\uff0c\u4f7f\u5176\u5b57\u7b26\u96c6\u548c\u6821\u5bf9\u89c4\u5219\u4e3a utf8mb4 \u548c utf8mb4_unicode_ci\u3002\u91cd\u542f mysql \u670d\u52a1\uff0c\u5373\u53ef\u751f\u6548\u3002\u9a8c\u8bc1\u8bbe\u7f6e\uff0c\u786e\u8ba4\u5b57\u7b26\u96c6\u548c\u6821\u5bf9\u89c4\u5219\u5df2\u66f4\u65b0\u3002 MySQL \u4e2d\u8bbe\u7f6e\u4e2d\u6587\u7684\u65b9\u6cd5 \u4e00\u3001\u914d\u7f6e my.cnf \u6587\u4ef6 \u6253\u5f00 MySQL \u914d\u7f6e\u6587\u4ef6 my.cnf\u3002\u8be5\u6587\u4ef6\u901a\u5e38\u4f4d\u4e8e\u4ee5\u4e0b\u4f4d\u7f6e\uff1a Windows\uff1aC:ProgramDataMySQLMySQL Server 8.0my.ini Linux\/macOS\uff1a\/etc\/\/my.cnf \u6dfb\u52a0\u6216\u7f16\u8f91\u4ee5\u4e0b\u884c\uff1a [mysqld] character-set-server=utf8mb4 collation-server=utf8mb4_unicode_ci \u767b\u5f55\u540e\u590d\u5236 \u4e8c\u3001\u66f4\u65b0\u6570\u636e\u5e93\u548c\u8868 \u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93\uff1a mysql -u root -p \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 \u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u66f4\u65b0\u6570\u636e\u5e93\u7684\u9ed8\u8ba4\u5b57\u7b26\u96c6\u548c\u6821\u5bf9\u89c4\u5219\uff1a ALTER DATABASE database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; \u767b\u5f55\u540e\u590d\u5236 [&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-5553","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5553","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=5553"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5553\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}