{"id":161099,"date":"2024-11-04T03:36:19","date_gmt":"2024-11-03T19:36:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/161099\/"},"modified":"2024-11-04T03:36:20","modified_gmt":"2024-11-03T19:36:20","slug":"%e7%8d%b2%e5%be%97-mysql-%e6%94%b9%e8%ae%8a%e5%ad%97%e7%ac%a6%e9%9b%86%e7%9a%84%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/161099\/","title":{"rendered":"\u7372\u5f97 MySQL \u6539\u8b8a\u5b57\u7b26\u96c6\u7684\u65b9\u6848"},"content":{"rendered":"<h1 id=\"%e7%8d%b2%e5%be%97-mysql-%e6%94%b9%e8%ae%8a%e5%ad%97%e7%ac%a6%e9%9b%86%e7%9a%84%e6%96%b9%e6%a1%88-KXqUglfwEB\">\u7372\u5f97 MySQL \u6539\u8b8a\u5b57\u7b26\u96c6\u7684\u65b9\u6848<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u5b57\u7b26\u96c6\u8a2d\u7f6e\u5c0d\u65bc\u78ba\u4fdd\u6578\u64da\u7684\u6b63\u78ba\u5b58\u5132\u548c\u6aa2\u7d22\u81f3\u95dc\u91cd\u8981\u3002MySQL \u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u5b57\u7b26\u96c6\u9078\u64c7\uff0c\u4ee5\u652f\u6301\u4e0d\u540c\u8a9e\u8a00\u548c\u7b26\u865f\u7684\u5b58\u5132\u9700\u6c42\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5728 MySQL \u4e2d\u6539\u8b8a\u5b57\u7b26\u96c6\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u65b9\u6848\u548c\u793a\u4f8b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e5%ad%97%e7%ac%a6%e9%9b%86%ef%bc%9f-KXqUglfwEB\">\u4ec0\u9ebc\u662f\u5b57\u7b26\u96c6\uff1f<\/h2>\n<p>\u5b57\u7b26\u96c6\u662f\u7528\u4f86\u5b9a\u7fa9\u5982\u4f55\u5728\u6578\u64da\u5eab\u4e2d\u5b58\u5132\u548c\u8868\u793a\u5b57\u7b26\u7684\u96c6\u5408\u3002\u6bcf\u500b\u5b57\u7b26\u96c6\u90fd\u5305\u542b\u4e00\u7d44\u5b57\u7b26\u53ca\u5176\u5c0d\u61c9\u7684\u7de8\u78bc\u65b9\u5f0f\u3002MySQL \u652f\u6301\u591a\u7a2e\u5b57\u7b26\u96c6\uff0c\u5982 <code>utf8<\/code>\u3001<code>utf8mb4<\/code>\u3001<code>latin1<\/code> \u7b49\u3002\u9078\u64c7\u5408\u9069\u7684\u5b57\u7b26\u96c6\u5c0d\u65bc\u78ba\u4fdd\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u53ef\u8b80\u6027\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e6%94%b9%e8%ae%8a%e5%ad%97%e7%ac%a6%e9%9b%86%ef%bc%9f-KXqUglfwEB\">\u70ba\u4ec0\u9ebc\u9700\u8981\u6539\u8b8a\u5b57\u7b26\u96c6\uff1f<\/h2>\n<p>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u6539\u8b8a MySQL \u7684\u5b57\u7b26\u96c6\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u7576\u60a8\u9700\u8981\u652f\u6301\u591a\u8a9e\u8a00\u5167\u5bb9\u6642\uff0c\u53ef\u80fd\u9700\u8981\u5f9e <code>latin1<\/code> \u8f49\u63db\u5230 <code>utf8mb4<\/code>\u3002<\/li>\n<li>\u7576\u60a8\u767c\u73fe\u6578\u64da\u5b58\u5132\u4e0d\u6b63\u78ba\u6216\u51fa\u73fe\u4e82\u78bc\u6642\uff0c\u9019\u901a\u5e38\u662f\u7531\u65bc\u5b57\u7b26\u96c6\u4e0d\u5339\u914d\u6240\u5c0e\u81f4\u7684\u3002<\/li>\n<li>\u5728\u5347\u7d1a\u6216\u9077\u79fb\u6578\u64da\u5eab\u6642\uff0c\u53ef\u80fd\u9700\u8981\u8abf\u6574\u5b57\u7b26\u96c6\u4ee5\u7b26\u5408\u65b0\u74b0\u5883\u7684\u8981\u6c42\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e6%94%b9%e8%ae%8a-mysql-%e7%9a%84%e5%ad%97%e7%ac%a6%e9%9b%86-KXqUglfwEB\">\u5982\u4f55\u6539\u8b8a MySQL \u7684\u5b57\u7b26\u96c6<\/h2>\n<p>\u6539\u8b8a MySQL \u7684\u5b57\u7b26\u96c6\u53ef\u4ee5\u5728\u591a\u500b\u5c64\u9762\u4e0a\u9032\u884c\uff0c\u5305\u62ec\u6578\u64da\u5eab\u3001\u8868\u548c\u5217\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5177\u9ad4\u7684\u6b65\u9a5f\u548c\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"1-%e6%94%b9%e8%ae%8a%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%ad%97%e7%ac%a6%e9%9b%86-KXqUglfwEB\">1. \u6539\u8b8a\u6578\u64da\u5eab\u7684\u5b57\u7b26\u96c6<\/h3>\n<p>\u8981\u6539\u8b8a\u6574\u500b\u6578\u64da\u5eab\u7684\u5b57\u7b26\u96c6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u8a9e\u53e5\uff1a<\/p>\n<pre><code>ALTER DATABASE database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;<\/code><\/pre>\n<p>\u9019\u5c07\u628a\u6307\u5b9a\u6578\u64da\u5eab\u7684\u5b57\u7b26\u96c6\u66f4\u6539\u70ba <code>utf8mb4<\/code>\uff0c\u4e26\u8a2d\u7f6e\u76f8\u61c9\u7684\u6392\u5e8f\u898f\u5247\u3002<\/p>\n<h3 id=\"2-%e6%94%b9%e8%ae%8a%e8%a1%a8%e7%9a%84%e5%ad%97%e7%ac%a6%e9%9b%86-KXqUglfwEB\">2. \u6539\u8b8a\u8868\u7684\u5b57\u7b26\u96c6<\/h3>\n<p>\u5982\u679c\u60a8\u53ea\u60f3\u6539\u8b8a\u67d0\u500b\u8868\u7684\u5b57\u7b26\u96c6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8a9e\u53e5\uff1a<\/p>\n<pre><code>ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;<\/code><\/pre>\n<p>\u9019\u5c07\u628a\u6307\u5b9a\u8868\u7684\u6240\u6709\u5217\u7684\u5b57\u7b26\u96c6\u66f4\u6539\u70ba <code>utf8mb4<\/code>\u3002<\/p>\n<h3 id=\"3-%e6%94%b9%e8%ae%8a%e5%88%97%e7%9a%84%e5%ad%97%e7%ac%a6%e9%9b%86-KXqUglfwEB\">3. \u6539\u8b8a\u5217\u7684\u5b57\u7b26\u96c6<\/h3>\n<p>\u5982\u679c\u60a8\u53ea\u9700\u8981\u6539\u8b8a\u67d0\u4e00\u5217\u7684\u5b57\u7b26\u96c6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8a9e\u53e5\uff1a<\/p>\n<pre><code>ALTER TABLE table_name MODIFY column_name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;<\/code><\/pre>\n<p>\u9019\u5c07\u628a\u6307\u5b9a\u5217\u7684\u5b57\u7b26\u96c6\u66f4\u6539\u70ba <code>utf8mb4<\/code>\u3002<\/p>\n<h2 id=\"%e6%aa%a2%e6%9f%a5%e7%95%b6%e5%89%8d%e5%ad%97%e7%ac%a6%e9%9b%86-KXqUglfwEB\">\u6aa2\u67e5\u7576\u524d\u5b57\u7b26\u96c6<\/h2>\n<p>\u5728\u9032\u884c\u5b57\u7b26\u96c6\u66f4\u6539\u4e4b\u524d\uff0c\u4e86\u89e3\u7576\u524d\u7684\u5b57\u7b26\u96c6\u8a2d\u7f6e\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u8a9e\u53e5\u4f86\u6aa2\u67e5\u7576\u524d\u6578\u64da\u5eab\u7684\u5b57\u7b26\u96c6\uff1a<\/p>\n<pre><code>SHOW VARIABLES LIKE 'character_set%';<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a MySQL \u4f3a\u670d\u5668\u7684\u5b57\u7b26\u96c6\u8a2d\u7f6e\uff0c\u5305\u62ec <code>character_set_database<\/code>\u3001<code>character_set_server<\/code> \u7b49\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-KXqUglfwEB\">\u7e3d\u7d50<\/h2>\n<p>\u6539\u8b8a MySQL \u7684\u5b57\u7b26\u96c6\u662f\u4e00\u500b\u91cd\u8981\u7684\u904e\u7a0b\uff0c\u80fd\u5920\u78ba\u4fdd\u6578\u64da\u7684\u6b63\u78ba\u5b58\u5132\u548c\u6aa2\u7d22\u3002\u7121\u8ad6\u662f\u5f9e\u6578\u64da\u5eab\u3001\u8868\u9084\u662f\u5217\u5c64\u9762\u9032\u884c\u66f4\u6539\uff0c\u4e86\u89e3\u5982\u4f55\u6b63\u78ba\u57f7\u884c\u9019\u4e9b\u64cd\u4f5c\u90fd\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u900f\u904e\u4e0a\u8ff0\u7684\u6b65\u9a5f\u548c\u793a\u4f8b\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406 MySQL \u7684\u5b57\u7b26\u96c6\u8a2d\u7f6e\uff0c\u907f\u514d\u6578\u64da\u4e82\u78bc\u548c\u4e0d\u517c\u5bb9\u7684\u554f\u984c\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u8f15\u9b06\u7ba1\u7406\u6578\u64da\u5eab\u548c\u61c9\u7528\u7a0b\u5e8f\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u670d\u52a1\u5668<\/a> \u9084\u662f <a href=\"https:\/\/server.hk\">\u4e91\u670d\u52a1\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u7372\u5f97 MySQL \u6539\u8b8a\u5b57\u7b26\u96c6\u7684\u65b9\u6848\uff0c\u63d0\u5347\u6578\u64da\u5eab\u517c\u5bb9\u6027\u8207\u6027\u80fd\uff0c\u78ba\u4fdd\u8cc7\u6599\u6b63\u78ba\u986f\u793a\u8207\u5b58\u5132\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-161099","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/161099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=161099"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/161099\/revisions"}],"predecessor-version":[{"id":161100,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/161099\/revisions\/161100"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=161099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=161099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=161099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}