{"id":163277,"date":"2024-11-04T22:09:23","date_gmt":"2024-11-04T14:09:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/163277\/"},"modified":"2024-11-04T22:09:24","modified_gmt":"2024-11-04T14:09:24","slug":"%e8%a7%a3%e6%b1%bamysql%e6%95%b8%e6%93%9a%e5%ba%ab%e7%b7%a8%e7%a2%bc%e5%95%8f%e9%a1%8c-%e4%bf%ae%e6%94%b9%e7%b7%a8%e7%a2%bc%e6%a0%bc%e5%bc%8f%e6%ad%a5%e9%a9%9f%ef%bc%88mysql%e6%95%b8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/163277\/","title":{"rendered":"\u89e3\u6c7aMySQL\u6578\u64da\u5eab\u7de8\u78bc\u554f\u984c\u2014\u2014\u4fee\u6539\u7de8\u78bc\u683c\u5f0f\u6b65\u9a5f\uff08MySQL\u6578\u64da\u5eab\u4fee\u6539\u7de8\u78bc\u683c\u5f0f\uff09"},"content":{"rendered":"<h1 id=\"%e8%a7%a3%e6%b1%bamysql%e6%95%b8%e6%93%9a%e5%ba%ab%e7%b7%a8%e7%a2%bc%e5%95%8f%e9%a1%8c-%e4%bf%ae%e6%94%b9%e7%b7%a8%e7%a2%bc%e6%a0%bc%e5%bc%8f%e6%ad%a5%e9%a9%9f-cbQxRnfYQG\">\u89e3\u6c7aMySQL\u6578\u64da\u5eab\u7de8\u78bc\u554f\u984c\u2014\u2014\u4fee\u6539\u7de8\u78bc\u683c\u5f0f\u6b65\u9a5f<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u7de8\u78bc\u683c\u5f0f\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\u652f\u6301\u591a\u7a2e\u7de8\u78bc\u683c\u5f0f\uff0c\u4f46\u5728\u5be6\u969b\u61c9\u7528\u4e2d\uff0c\u7de8\u78bc\u4e0d\u4e00\u81f4\u53ef\u80fd\u5c0e\u81f4\u6578\u64da\u986f\u793a\u932f\u8aa4\u6216\u4e1f\u5931\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u89e3\u6c7aMySQL\u6578\u64da\u5eab\u7684\u7de8\u78bc\u554f\u984c\uff0c\u4e26\u63d0\u4f9b\u5177\u9ad4\u7684\u4fee\u6539\u7de8\u78bc\u683c\u5f0f\u6b65\u9a5f\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e4%bf%ae%e6%94%b9%e7%b7%a8%e7%a2%bc%e6%a0%bc%e5%bc%8f-cbQxRnfYQG\">\u70ba\u4ec0\u9ebc\u9700\u8981\u4fee\u6539\u7de8\u78bc\u683c\u5f0f<\/h2>\n<p>\u6578\u64da\u5eab\u7684\u7de8\u78bc\u683c\u5f0f\u6c7a\u5b9a\u4e86\u5982\u4f55\u5b58\u5132\u548c\u986f\u793a\u5b57\u7b26\u3002\u5982\u679c\u6578\u64da\u5eab\u7684\u7de8\u78bc\u683c\u5f0f\u8207\u61c9\u7528\u7a0b\u5e8f\u6216\u7528\u6236\u7aef\u7684\u7de8\u78bc\u683c\u5f0f\u4e0d\u4e00\u81f4\uff0c\u53ef\u80fd\u6703\u51fa\u73fe\u4e82\u78bc\u6216\u6578\u64da\u4e1f\u5931\u7684\u60c5\u6cc1\u3002\u4f8b\u5982\uff0c\u7576\u6578\u64da\u5eab\u4f7f\u7528UTF-8\u7de8\u78bc\uff0c\u800c\u61c9\u7528\u7a0b\u5e8f\u4f7f\u7528ISO-8859-1\u7de8\u78bc\u6642\uff0c\u5f9e\u6578\u64da\u5eab\u6aa2\u7d22\u7684\u6578\u64da\u53ef\u80fd\u6703\u986f\u793a\u70ba\u4e82\u78bc\u3002<\/p>\n<h2 id=\"mysql%e7%b7%a8%e7%a2%bc%e6%a0%bc%e5%bc%8f%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-cbQxRnfYQG\">MySQL\u7de8\u78bc\u683c\u5f0f\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>MySQL\u652f\u6301\u591a\u7a2e\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u898f\u5247\u3002\u5b57\u7b26\u96c6\u5b9a\u7fa9\u4e86\u53ef\u7528\u7684\u5b57\u7b26\uff0c\u800c\u6392\u5e8f\u898f\u5247\u5247\u5b9a\u7fa9\u4e86\u5b57\u7b26\u7684\u6392\u5e8f\u65b9\u5f0f\u3002\u5e38\u898b\u7684\u5b57\u7b26\u96c6\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>utf8<\/strong>\uff1a\u652f\u6301\u5927\u591a\u6578\u8a9e\u8a00\u7684\u5b57\u7b26\uff0c\u9069\u5408\u591a\u8a9e\u8a00\u61c9\u7528\u3002<\/li>\n<li><strong>utf8mb4<\/strong>\uff1a\u64f4\u5c55\u7684UTF-8\uff0c\u652f\u6301\u66f4\u591aUnicode\u5b57\u7b26\uff0c\u5305\u62ec\u8868\u60c5\u7b26\u865f\u3002<\/li>\n<li><strong>latin1<\/strong>\uff1a\u4e3b\u8981\u7528\u65bc\u897f\u6b50\u8a9e\u8a00\uff0c\u5b57\u7b26\u7bc4\u570d\u8f03\u5c0f\u3002<\/li>\n<\/ul>\n<h2 id=\"%e4%bf%ae%e6%94%b9mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e7%b7%a8%e7%a2%bc%e6%a0%bc%e5%bc%8f%e7%9a%84%e6%ad%a5%e9%a9%9f-cbQxRnfYQG\">\u4fee\u6539MySQL\u6578\u64da\u5eab\u7de8\u78bc\u683c\u5f0f\u7684\u6b65\u9a5f<\/h2>\n<h3 id=\"%e6%ad%a5%e9%a9%9f%e4%b8%80%ef%bc%9a%e6%aa%a2%e6%9f%a5%e7%95%b6%e5%89%8d%e7%b7%a8%e7%a2%bc%e6%a0%bc%e5%bc%8f-cbQxRnfYQG\">\u6b65\u9a5f\u4e00\uff1a\u6aa2\u67e5\u7576\u524d\u7de8\u78bc\u683c\u5f0f<\/h3>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u6aa2\u67e5\u7576\u524d\u6578\u64da\u5eab\u548c\u8868\u7684\u7de8\u78bc\u683c\u5f0f\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0bSQL\u67e5\u8a62\u4f86\u67e5\u770b\u6578\u64da\u5eab\u7684\u7de8\u78bc\uff1a<\/p>\n<pre><code>SHOW VARIABLES LIKE 'character_set_database';<\/code><\/pre>\n<p>\u8981\u6aa2\u67e5\u7279\u5b9a\u8868\u7684\u7de8\u78bc\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>SHOW TABLE STATUS LIKE 'your_table_name';<\/code><\/pre>\n<h3 id=\"%e6%ad%a5%e9%a9%9f%e4%ba%8c%ef%bc%9a%e4%bf%ae%e6%94%b9%e6%95%b8%e6%93%9a%e5%ba%ab%e7%b7%a8%e7%a2%bc%e6%a0%bc%e5%bc%8f-cbQxRnfYQG\">\u6b65\u9a5f\u4e8c\uff1a\u4fee\u6539\u6578\u64da\u5eab\u7de8\u78bc\u683c\u5f0f<\/h3>\n<p>\u5982\u679c\u9700\u8981\u4fee\u6539\u6578\u64da\u5eab\u7684\u7de8\u78bc\u683c\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0bSQL\u547d\u4ee4\uff1a<\/p>\n<pre><code>ALTER DATABASE your_database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;<\/code><\/pre>\n<p>\u9019\u5c07\u628a\u6578\u64da\u5eab\u7684\u7de8\u78bc\u683c\u5f0f\u66f4\u6539\u70bautf8mb4\uff0c\u4e26\u8a2d\u7f6e\u76f8\u61c9\u7684\u6392\u5e8f\u898f\u5247\u3002<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f%e4%b8%89%ef%bc%9a%e4%bf%ae%e6%94%b9%e8%a1%a8%e7%9a%84%e7%b7%a8%e7%a2%bc%e6%a0%bc%e5%bc%8f-cbQxRnfYQG\">\u6b65\u9a5f\u4e09\uff1a\u4fee\u6539\u8868\u7684\u7de8\u78bc\u683c\u5f0f<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u4fee\u6539\u8868\u7684\u7de8\u78bc\u683c\u5f0f\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>ALTER TABLE your_table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;<\/code><\/pre>\n<p>\u9019\u5c07\u628a\u6307\u5b9a\u8868\u7684\u7de8\u78bc\u683c\u5f0f\u66f4\u6539\u70bautf8mb4\u3002<\/p>\n<h3 id=\"%e6%ad%a5%e9%a9%9f%e5%9b%9b%ef%bc%9a%e4%bf%ae%e6%94%b9%e5%88%97%e7%9a%84%e7%b7%a8%e7%a2%bc%e6%a0%bc%e5%bc%8f-cbQxRnfYQG\">\u6b65\u9a5f\u56db\uff1a\u4fee\u6539\u5217\u7684\u7de8\u78bc\u683c\u5f0f<\/h3>\n<p>\u5982\u679c\u9700\u8981\u55ae\u7368\u4fee\u6539\u67d0\u4e00\u5217\u7684\u7de8\u78bc\u683c\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>ALTER TABLE your_table_name MODIFY your_column_name VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6%e7%b7%a8%e7%a2%bc%e4%bf%ae%e6%94%b9%e6%98%af%e5%90%a6%e6%88%90%e5%8a%9f-cbQxRnfYQG\">\u6e2c\u8a66\u7de8\u78bc\u4fee\u6539\u662f\u5426\u6210\u529f<\/h2>\n<p>\u5b8c\u6210\u7de8\u78bc\u4fee\u6539\u5f8c\uff0c\u5efa\u8b70\u9032\u884c\u6e2c\u8a66\u4ee5\u78ba\u4fdd\u6578\u64da\u80fd\u5920\u6b63\u78ba\u986f\u793a\u3002\u53ef\u4ee5\u63d2\u5165\u4e00\u4e9b\u5305\u542b\u7279\u6b8a\u5b57\u7b26\u7684\u6578\u64da\uff0c\u7136\u5f8c\u6aa2\u7d22\u9019\u4e9b\u6578\u64da\u4ee5\u6aa2\u67e5\u986f\u793a\u662f\u5426\u6b63\u5e38\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-cbQxRnfYQG\">\u7e3d\u7d50<\/h2>\n<p>\u5728MySQL\u4e2d\uff0c\u6b63\u78ba\u7684\u7de8\u78bc\u683c\u5f0f\u5c0d\u65bc\u6578\u64da\u7684\u5b8c\u6574\u6027\u548c\u53ef\u8b80\u6027\u81f3\u95dc\u91cd\u8981\u3002\u901a\u904e\u4e0a\u8ff0\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u6c7aMySQL\u6578\u64da\u5eab\u7684\u7de8\u78bc\u554f\u984c\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u6b63\u78ba\u5b58\u5132\u548c\u6aa2\u7d22\u3002\u5982\u679c\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u670d\u52d9\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u6578\u64da\u5eab\u7ba1\u7406\u63d0\u4f9b\u7a69\u5b9a\u7684\u74b0\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u6c7aMySQL\u6578\u64da\u5eab\u7de8\u78bc\u554f\u984c\uff0c\u8a73\u7d30\u6b65\u9a5f\u6559\u4f60\u5982\u4f55\u4fee\u6539\u7de8\u78bc\u683c\u5f0f\uff0c\u78ba\u4fdd\u6578\u64da\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-163277","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/163277","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=163277"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/163277\/revisions"}],"predecessor-version":[{"id":163278,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/163277\/revisions\/163278"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=163277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=163277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=163277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}