{"id":62339,"date":"2024-10-13T18:11:15","date_gmt":"2024-10-13T10:11:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/62339\/"},"modified":"2024-10-13T18:11:15","modified_gmt":"2024-10-13T10:11:15","slug":"liunx%e7%92%b0%e5%a2%83%e4%b8%8bmysql%e5%ad%97%e7%ac%a6%e9%9b%86%e7%9a%84%e4%bf%ae%e6%94%b9%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/62339\/","title":{"rendered":"Liunx\u74b0\u5883\u4e0bMySQL\u5b57\u7b26\u96c6\u7684\u4fee\u6539\u65b9\u6cd5"},"content":{"rendered":"<h1 id=\"linux%e7%92%b0%e5%a2%83%e4%b8%8bmysql%e5%ad%97%e7%ac%a6%e9%9b%86%e7%9a%84%e4%bf%ae%e6%94%b9%e6%96%b9%e6%b3%95-ZptybLguBC\">Linux\u74b0\u5883\u4e0bMySQL\u5b57\u7b26\u96c6\u7684\u4fee\u6539\u65b9\u6cd5<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u5b57\u7b26\u96c6\u914d\u7f6e\u5c0d\u65bc\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u517c\u5bb9\u6027\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\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u898f\u5247\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5728Linux\u74b0\u5883\u4e0b\u5982\u4f55\u4fee\u6539MySQL\u7684\u5b57\u7b26\u96c6\uff0c\u4ee5\u78ba\u4fdd\u6578\u64da\u7684\u6b63\u78ba\u5b58\u5132\u548c\u6aa2\u7d22\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%e5%ad%97%e7%ac%a6%e9%9b%86%ef%bc%9f-ZptybLguBC\">\u70ba\u4ec0\u9ebc\u9700\u8981\u4fee\u6539\u5b57\u7b26\u96c6\uff1f<\/h2>\n<p>\u5b57\u7b26\u96c6\u7684\u9078\u64c7\u76f4\u63a5\u5f71\u97ff\u5230\u6578\u64da\u7684\u5b58\u5132\u65b9\u5f0f\u548c\u67e5\u8a62\u6548\u7387\u3002\u82e5\u5b57\u7b26\u96c6\u4e0d\u5339\u914d\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u6578\u64da\u4e1f\u5931\u6216\u986f\u793a\u932f\u8aa4\u3002\u4f8b\u5982\uff0c\u82e5\u61c9\u7528\u7a0b\u5e8f\u4f7f\u7528UTF-8\u5b57\u7b26\u96c6\uff0c\u4f46\u6578\u64da\u5eab\u537b\u4f7f\u7528Latin1\uff0c\u5247\u5728\u5b58\u5132\u4e2d\u6587\u5b57\u7b26\u6642\u53ef\u80fd\u6703\u51fa\u73fe\u554f\u984c\u3002\u56e0\u6b64\uff0c\u6839\u64da\u61c9\u7528\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u5b57\u7b26\u96c6\u662f\u975e\u5e38\u91cd\u8981\u7684\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-ZptybLguBC\">\u6aa2\u67e5\u7576\u524d\u5b57\u7b26\u96c6<\/h2>\n<p>\u5728\u4fee\u6539\u5b57\u7b26\u96c6\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u6aa2\u67e5\u7576\u524d\u7684\u5b57\u7b26\u96c6\u8a2d\u7f6e\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0bSQL\u547d\u4ee4\u4f86\u67e5\u770b\u7576\u524d\u7684\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u898f\u5247\uff1a<\/p>\n<pre><code>SHOW VARIABLES LIKE 'character_set%';<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793aMySQL\u7684\u5168\u5c40\u5b57\u7b26\u96c6\u8a2d\u7f6e\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>character_set_client<\/li>\n<li>character_set_connection<\/li>\n<li>character_set_database<\/li>\n<li>character_set_results<\/li>\n<li>character_set_server<\/li>\n<\/ul>\n<h2 id=\"%e4%bf%ae%e6%94%b9%e5%ad%97%e7%ac%a6%e9%9b%86-ZptybLguBC\">\u4fee\u6539\u5b57\u7b26\u96c6<\/h2>\n<p>\u8981\u4fee\u6539MySQL\u7684\u5b57\u7b26\u96c6\uff0c\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\u4f86\u5b8c\u6210\uff1a<\/p>\n<h3 id=\"1-%e4%bf%ae%e6%94%b9%e9%85%8d%e7%bd%ae%e6%96%87%e4%bb%b6-ZptybLguBC\">1. \u4fee\u6539\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u9996\u5148\uff0c\u627e\u5230MySQL\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u901a\u5e38\u4f4d\u65bc\/etc\/my.cnf\u6216\/etc\/mysql\/my.cnf\u3002\u4f7f\u7528\u6587\u672c\u7de8\u8f2f\u5668\u6253\u958b\u8a72\u6587\u4ef6\uff0c\u4e26\u6dfb\u52a0\u6216\u4fee\u6539\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre><code>[mysqld]\ncharacter-set-server=utf8mb4\ncollation-server=utf8mb4_unicode_ci\n\n[client]\ndefault-character-set=utf8mb4<\/code><\/pre>\n<p>\u9019\u88e1\u5c07\u5b57\u7b26\u96c6\u8a2d\u7f6e\u70bautf8mb4\uff0c\u9019\u662f\u4e00\u500b\u652f\u6301\u6240\u6709Unicode\u5b57\u7b26\u7684\u5b57\u7b26\u96c6\uff0c\u9069\u5408\u5b58\u5132\u591a\u8a9e\u8a00\u6578\u64da\u3002<\/p>\n<h3 id=\"2-%e9%87%8d%e5%95%9fmysql%e6%9c%8d%e5%8b%99-ZptybLguBC\">2. \u91cd\u555fMySQL\u670d\u52d9<\/h3>\n<p>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u5f8c\uff0c\u9700\u8981\u91cd\u555fMySQL\u670d\u52d9\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u91cd\u555f\u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl restart mysql<\/code><\/pre>\n<h3 id=\"3-%e4%bf%ae%e6%94%b9%e7%8f%be%e6%9c%89%e6%95%b8%e6%93%9a%e5%ba%ab%e5%92%8c%e8%a1%a8%e7%9a%84%e5%ad%97%e7%ac%a6%e9%9b%86-ZptybLguBC\">3. \u4fee\u6539\u73fe\u6709\u6578\u64da\u5eab\u548c\u8868\u7684\u5b57\u7b26\u96c6<\/h3>\n<p>\u5982\u679c\u9700\u8981\u4fee\u6539\u73fe\u6709\u6578\u64da\u5eab\u6216\u8868\u7684\u5b57\u7b26\u96c6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0bSQL\u547d\u4ee4\uff1a<\/p>\n<pre><code>ALTER DATABASE database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;<\/code><\/pre>\n<pre><code>ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;<\/code><\/pre>\n<p>\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u6578\u64da\u5eab\u548c\u8868\u4e2d\u7684\u6240\u6709\u6578\u64da\u90fd\u4f7f\u7528\u65b0\u7684\u5b57\u7b26\u96c6\u9032\u884c\u5b58\u5132\u3002<\/p>\n<h2 id=\"%e9%a9%97%e8%ad%89%e4%bf%ae%e6%94%b9%e7%b5%90%e6%9e%9c-ZptybLguBC\">\u9a57\u8b49\u4fee\u6539\u7d50\u679c<\/h2>\n<p>\u5b8c\u6210\u4e0a\u8ff0\u6b65\u9a5f\u5f8c\uff0c\u53ef\u4ee5\u518d\u6b21\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u6aa2\u67e5\u5b57\u7b26\u96c6\u662f\u5426\u5df2\u6210\u529f\u4fee\u6539\uff1a<\/p>\n<pre><code>SHOW VARIABLES LIKE 'character_set%';<\/code><\/pre>\n<p>\u78ba\u4fdd\u6240\u6709\u76f8\u95dc\u7684\u5b57\u7b26\u96c6\u8a2d\u7f6e\u90fd\u5df2\u66f4\u65b0\u70bautf8mb4\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-ZptybLguBC\">\u7e3d\u7d50<\/h2>\n<p>\u5728Linux\u74b0\u5883\u4e0b\u4fee\u6539MySQL\u7684\u5b57\u7b26\u96c6\u662f\u4e00\u500b\u91cd\u8981\u7684\u6b65\u9a5f\uff0c\u80fd\u5920\u78ba\u4fdd\u6578\u64da\u7684\u6b63\u78ba\u5b58\u5132\u548c\u6aa2\u7d22\u3002\u901a\u904e\u6aa2\u67e5\u7576\u524d\u5b57\u7b26\u96c6\u3001\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u3001\u91cd\u555f\u670d\u52d9\u4ee5\u53ca\u66f4\u65b0\u73fe\u6709\u6578\u64da\u5eab\u548c\u8868\u7684\u5b57\u7b26\u96c6\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u6c7a\u5b57\u7b26\u96c6\u4e0d\u5339\u914d\u7684\u554f\u984c\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u61c9\u7528\u4f86\u8aaa\uff0c\u9078\u64c7\u5408\u9069\u7684\u5b57\u7b26\u96c6\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\u4ee5\u6eff\u8db3\u60a8\u7684\u9700\u6c42\uff0c\u7121\u8ad6\u662f\u6578\u64da\u5eab\u7ba1\u7406\u9084\u662f\u5176\u4ed6\u61c9\u7528\u7a0b\u5e8f\u7684\u90e8\u7f72\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5728Linux\u74b0\u5883\u4e0b\u5982\u4f55\u4fee\u6539MySQL\u5b57\u7b26\u96c6\uff0c\u78ba\u4fdd\u6578\u64da\u6b63\u78ba\u986f\u793a\u548c\u5b58\u5132\uff0c\u63d0\u5347\u6578\u64da\u5eab\u6027\u80fd\u8207\u517c\u5bb9\u6027\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-62339","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62339","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=62339"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62339\/revisions"}],"predecessor-version":[{"id":62340,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/62339\/revisions\/62340"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=62339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=62339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=62339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}