{"id":6011,"date":"2024-11-14T12:48:36","date_gmt":"2024-11-14T04:48:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6011\/"},"modified":"2024-11-14T12:48:36","modified_gmt":"2024-11-14T04:48:36","slug":"mysql1251%e9%94%99%e8%af%af%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6011\/","title":{"rendered":"mysql1251\u9519\u8bef\u5982\u4f55\u89e3\u51b3"},"content":{"rendered":"<blockquote><p>\n  mysql 1251 \u9519\u8bef\u8868\u793a\u5b57\u7b26\u96c6\u4e0d\u5339\u914d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u89e3\u51b3\uff1a\u68c0\u67e5\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\u7684\u4e00\u81f4\u6027\u3002\u8f6c\u6362\u6570\u636e\u4ee5\u5339\u914d\u76ee\u6807\u5b57\u7b26\u96c6\u3002\u4f7f\u7528\u517c\u5bb9\u5b57\u7b26\u96c6\uff08\u4f8b\u5982 utf-8\uff09\u3002\u542f\u7528 mysql \u7684\u5b57\u7b26\u96c6\u8f6c\u6362\u529f\u80fd\u3002\u7981\u7528 mysql \u7684\u4e25\u683c\u6a21\u5f0f\u3002\u68c0\u67e5\u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u5b57\u7b26\u96c6\u8bbe\u7f6e\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/12\/2024061215122592761.jpg\" class=\"aligncenter\" title=\"mysql1251\u9519\u8bef\u5982\u4f55\u89e3\u51b3\u63d2\u56fe\" alt=\"mysql1251\u9519\u8bef\u5982\u4f55\u89e3\u51b3\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL 1251 \u9519\u8bef\u7684\u89e3\u51b3\u65b9\u6cd5<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong>MySQL 1251 \u9519\u8bef\u662f\u4ec0\u4e48\uff1f<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong>MySQL 1251 \u9519\u8bef\u8868\u793a\u5b57\u7b26\u96c6\u4e0d\u5339\u914d\uff0c\u901a\u5e38\u53d1\u751f\u5728\u4f60\u5c1d\u8bd5\u5728\u4e0d\u540c\u7684\u5b57\u7b26\u96c6\u8868\u6216\u5217\u4e4b\u95f4\u63d2\u5165\u6216\u66f4\u65b0\u6570\u636e\u65f6\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p><strong>1. \u68c0\u67e5\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u8868\u548c\u5217\u7684\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\u662f\u4e00\u81f4\u7684\u3002<\/li>\n<li>\u4f7f\u7528 SHOW CREATE TABLE table_name \u547d\u4ee4\u68c0\u67e5\u8868\u7ed3\u6784\u3002<\/li>\n<li>\u4f7f\u7528 ALTER TABLE table_name CONVERT TO CHARACTER SET charset_name COLLATE collation_name \u547d\u4ee4\u66f4\u6539\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\u3002<\/li>\n<\/ul>\n<p><strong>2. \u8f6c\u6362\u6570\u636e<\/strong><\/p>\n<ul>\n<li>\u5728\u5c06\u6570\u636e\u63d2\u5165\u6216\u66f4\u65b0\u8868\u4e4b\u524d\uff0c\u5c06\u5176\u8f6c\u6362\u4e3a\u5339\u914d\u7684\u5b57\u7b26\u96c6\u3002<\/li>\n<li>\u4f7f\u7528 CONVERT() \u51fd\u6570\u5c06\u6570\u636e\u8f6c\u6362\u4e3a\u4e0d\u540c\u7684\u5b57\u7b26\u96c6\u3002<\/li>\n<li>\u4f8b\u5982\uff1aINSERT INTO table_name (column_name) VALUES (CONVERT(&#8216;string&#8217; USING utf8mb4))<\/li>\n<\/ul>\n<p><strong>3. \u4f7f\u7528\u517c\u5bb9\u5b57\u7b26\u96c6<\/strong><\/p>\n<ul>\n<li>\u5bf9\u4e8e\u6d89\u53ca\u4e0d\u540c\u8bed\u8a00\u6216\u5b57\u7b26\u96c6\u7684\u6570\u636e\uff0c\u8bf7\u4f7f\u7528\u517c\u5bb9\u7684\u5b57\u7b26\u96c6\uff0c\u4f8b\u5982 UTF-8\u3002<\/li>\n<li>\u786e\u4fdd\u6240\u6709\u8868\u548c\u5217\u90fd\u4f7f\u7528\u76f8\u540c\u7684\u517c\u5bb9\u5b57\u7b26\u96c6\u3002<\/li>\n<\/ul>\n<p><strong>4. \u542f\u7528\u8f6c\u6362<\/strong><\/p>\n<ul>\n<li>\u542f\u4f5c\u7528\u4e8e MySQL \u7684\u5b57\u7b26\u96c6\u8f6c\u6362\u529f\u80fd\u3002<\/li>\n<li>\u8bbe\u7f6e character_set_server \u548c collation_server \u7cfb\u7edf\u53d8\u91cf\u4ee5\u6307\u5b9a\u9ed8\u8ba4\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\u3002<\/li>\n<li>\u4f7f\u7528 SET NAMES charset_name COLLATE collation_name \u8bed\u53e5\u6307\u5b9a\u4f1a\u8bdd\u671f\u95f4\u7684\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\u3002<\/li>\n<\/ul>\n<p><strong>5. \u7981\u7528\u4e25\u683c\u6a21\u5f0f<\/strong><\/p>\n<ul>\n<li>\u7981\u7528 MySQL \u7684\u4e25\u683c\u6a21\u5f0f\uff0c\u5b83\u53ef\u4ee5\u9632\u6b62\u5b57\u7b26\u96c6\u4e0d\u5339\u914d\u7684\u9519\u8bef\u3002<\/li>\n<li>\u8bbe\u7f6e sql_mode \u7cfb\u7edf\u53d8\u91cf\u4e3a NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION \u4ee5\u7981\u7528\u4e25\u683c\u6a21\u5f0f\u3002<\/li>\n<\/ul>\n<p><strong>6. \u4fee\u6539\u5ba2\u6237\u7aef\u8fde\u63a5<\/strong><\/p>\n<ul>\n<li>\u68c0\u67e5\u5ba2\u6237\u7aef\u5e94\u7528\u7a0b\u5e8f\uff08\u5982 PHP \u6216 Java\uff09\u662f\u5426\u6b63\u786e\u6307\u5b9a\u4e86\u5b57\u7b26\u96c6\u3002<\/li>\n<li>\u8bbe\u7f6e\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8fde\u63a5\u5bf9\u8c61\u7684\u5b57\u7b26\u96c6\u5c5e\u6027\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f1251\u9519\u8bef\u5982\u4f55\u89e3\u51b3\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 1251 \u9519\u8bef\u8868\u793a\u5b57\u7b26\u96c6\u4e0d\u5339\u914d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u89e3\u51b3\uff1a\u68c0\u67e5\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\u7684\u4e00\u81f4\u6027\u3002\u8f6c\u6362\u6570\u636e\u4ee5\u5339\u914d\u76ee\u6807\u5b57\u7b26\u96c6\u3002\u4f7f\u7528\u517c\u5bb9\u5b57\u7b26\u96c6\uff08\u4f8b\u5982 utf-8\uff09\u3002\u542f\u7528 mysql \u7684\u5b57\u7b26\u96c6\u8f6c\u6362\u529f\u80fd\u3002\u7981\u7528 mysql \u7684\u4e25\u683c\u6a21\u5f0f\u3002\u68c0\u67e5\u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u5b57\u7b26\u96c6\u8bbe\u7f6e\u3002 MySQL 1251 \u9519\u8bef\u7684\u89e3\u51b3\u65b9\u6cd5 \u95ee\u9898\uff1aMySQL 1251 \u9519\u8bef\u662f\u4ec0\u4e48\uff1f \u89e3\u7b54\uff1aMySQL 1251 \u9519\u8bef\u8868\u793a\u5b57\u7b26\u96c6\u4e0d\u5339\u914d\uff0c\u901a\u5e38\u53d1\u751f\u5728\u4f60\u5c1d\u8bd5\u5728\u4e0d\u540c\u7684\u5b57\u7b26\u96c6\u8868\u6216\u5217\u4e4b\u95f4\u63d2\u5165\u6216\u66f4\u65b0\u6570\u636e\u65f6\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a 1. \u68c0\u67e5\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219 \u786e\u4fdd\u8868\u548c\u5217\u7684\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\u662f\u4e00\u81f4\u7684\u3002 \u4f7f\u7528 SHOW CREATE TABLE table_name \u547d\u4ee4\u68c0\u67e5\u8868\u7ed3\u6784\u3002 \u4f7f\u7528 ALTER TABLE table_name CONVERT TO CHARACTER SET charset_name COLLATE collation_name \u547d\u4ee4\u66f4\u6539\u5b57\u7b26\u96c6\u548c\u6392\u5e8f\u89c4\u5219\u3002 2. \u8f6c\u6362\u6570\u636e \u5728\u5c06\u6570\u636e\u63d2\u5165\u6216\u66f4\u65b0\u8868\u4e4b\u524d\uff0c\u5c06\u5176\u8f6c\u6362\u4e3a\u5339\u914d\u7684\u5b57\u7b26\u96c6\u3002 \u4f7f\u7528 CONVERT() \u51fd\u6570\u5c06\u6570\u636e\u8f6c\u6362\u4e3a\u4e0d\u540c\u7684\u5b57\u7b26\u96c6\u3002 \u4f8b\u5982\uff1aINSERT INTO table_name (column_name) VALUES (CONVERT(&#8216;string&#8217; USING utf8mb4)) 3. \u4f7f\u7528\u517c\u5bb9\u5b57\u7b26\u96c6 [&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-6011","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6011","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=6011"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6011\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}