{"id":709,"date":"2014-01-12T10:40:30","date_gmt":"2014-01-12T02:40:30","guid":{"rendered":"http:\/\/coderbee.net\/?p=709"},"modified":"2014-01-12T10:40:30","modified_gmt":"2014-01-12T02:40:30","slug":"mysql-%e4%b9%b1%e7%a0%81-%e4%b8%8e-%e5%ad%97%e7%ac%a6%e9%9b%86","status":"publish","type":"post","link":"https:\/\/coderbee.net\/index.php\/db\/20140112\/709","title":{"rendered":"MySQL \u4e71\u7801 \u4e0e \u5b57\u7b26\u96c6"},"content":{"rendered":"<p>MySQL \u5b89\u88c5\u540e\u9ed8\u8ba4\u7684\u5b57\u7b26\u96c6\u662f <code>latin1<\/code>\uff0c\u8fd9\u6837\u5728\u5904\u7406\u4e2d\u6587\u65f6\u5bb9\u6613\u51fa\u73b0\u4e71\u7801\u95ee\u9898\uff0c\u6240\u4ee5\u9700\u8981\u6539\u4e3a <code>utf8<\/code>\u3002<\/p>\n<p>\u6ce8\uff1a\u6211\u7684MySQL\u7248\u672c\u662f<code>5.6.*<\/code>\u3002<\/p>\n<p>\u7528\u8bed\u53e5 <code>show variables like 'character%';<\/code> \u67e5\u770bMySQL\u5f53\u524d\u7684\u5b57\u7b26\u96c6\u8bbe\u7f6e\uff08\u4e5f\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4 <code>status<\/code>\u67e5\u770b\uff09\uff1a<\/p>\n<pre>\nmysql> show variables like 'character%';\n+--------------------------+----------------------------------+\n| Variable_name            | Value                            |\n+--------------------------+----------------------------------+\n| character_set_client     | latin1                           |\n| character_set_connection | latin1                           |\n| character_set_database   | latin1                           |\n| character_set_filesystem | binary                           |\n| character_set_results    | latin1                           |\n| character_set_server     | latin1                           |\n| character_set_system     | utf8                             |\n| character_sets_dir       | \/usr\/share\/mysql\/share\/charsets\/ |\n+--------------------------+----------------------------------+\n8 rows in set (0.03 sec)\n<\/pre>\n<p>\u4ece\u7ed3\u679c\u53ef\u4ee5\u770b\u51fa\uff0cMySQL\u5b57\u7b26\u96c6\u6d89\u53ca\u5230\uff1a<\/p>\n<ul>\n<li>\u5ba2\u6237\u7aef\u4f7f\u7528\u7684\u5b57\u7b26\u96c6\uff1acharacter_set_client<\/li>\n<li>\u5ba2\u6237\u7aef\u57df\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u8fde\u63a5\u4f7f\u7528\u7684\u5b57\u7b26\u96c6\uff1acharacter_set_connection<\/li>\n<li>\u6570\u636e\u5e93\u5b9e\u4f8b\u4f7f\u7528\u7684\u5b57\u7b26\u96c6\uff1acharacter_set_database<\/li>\n<li>MySQL\u670d\u52a1\u5668\u4f7f\u7528\u7684\u5b57\u7b26\u96c6\uff1acharacter_set_serve<br \/>\n<!--more--><\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u5b57\u7b26\u96c6\u90fd\u53ef\u4ee5\u5728\u914d\u7f6e\u6587\u4ef6 <code>my.cnf<\/code> \u91cc\u914d\u7f6e\uff0c\u589e\u52a0\u5982\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre>\n[client]\ndefault-character-set=utf8\n\n[mysql]\ndefault-character-set=utf8\n\n[mysqld]\ncharacter-set-server=utf8\n<\/pre>\n<p>\u4fee\u6539\u540e\u8981\u91cd\u542fMySQL\u670d\u52a1\u3002<\/p>\n<p>\u5bf9\u4e8e\u5df2\u521b\u5efa\u7684\u6570\u636e\u5e93\u5b9e\u4f8b\u7684\u7f16\u7801\uff0c\u53ef\u4ee5\u7528\u8bed\u53e5 <code>alert database blog character set utf8;<\/code> \u4fee\u6539\u3002<\/p>\n<p>\u5bf9\u4e8e\u5df2\u767b\u5f55\u7684\u4f1a\u8bdd\uff0c\u53ef\u4ee5\u7528\u8bed\u53e5 <code>set names utf8;<\/code> \u6765\u4fee\u6539\u5f53\u524d\u4f1a\u8bdd\u7684\u5b57\u7b26\u96c6\uff0c\u5b83\u4f1a\u628a <code>character_set_client\uff0ccharacter_set_connection\uff0ccharacter_set_results<\/code> \u4fee\u6539\u4e3a <code>utf8<\/code>\u7f16\u7801\uff0c\u53ea\u5bf9\u5f53\u524d\u4f1a\u8bdd\u6709\u6548\uff0c\u6bcf\u6b21\u767b\u5f55\u8981\u91cd\u65b0\u8bbe\u7f6e\u3002<\/p>\n<p>\u5982\u679c\u521b\u5efa\u8868\u7684\u65f6\u5019\u6ca1\u6709\u6307\u5b9a\u5b57\u7b26\u7f16\u7801\uff0c\u4e5f\u662f <code>latin1<\/code>\u7684\uff0c\u4e14\u8868\u91cc\u7684\u6570\u636e\u4e5f\u8fd9\u6837\uff0c\u8fd9\u65f6\u5c31\u9700\u8981\u628a\u8868\u7ed3\u6784\u548c\u6570\u636e\u5206\u522b\u7528  <code>latin1<\/code> \u7f16\u7801\u5bfc\u51fa\u6765\uff0c\u518d\u628a\u8868\u7684\u521b\u5efa\u8bed\u53e5\u91cc\u6307\u5b9a\u4e3a <code>utf8<\/code>\uff0c\u540c\u65f6\u628a\u6570\u636e\u7684 <code>sql<\/code> \u6587\u4ef6\u4e5f\u6539\u4e3a <code>utf8<\/code>\uff0c\u53ef\u4ee5\u5728\u672c\u5730\u7684\u6587\u672c\u7f16\u8f91\u5668\u91cc\u4fee\u6539\uff0c\u7136\u540e\u518d\u628a\u6570\u636e\u91cd\u65b0\u5bfc\u5165\u3002<\/p>\n<hr\/>\n<p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u5fae\u4fe1\u516c\u4f17\u53f7: <strong>coderbee\u7b14\u8bb0<\/strong>\uff0c\u53ef\u4ee5\u66f4\u53ca\u65f6\u56de\u590d\u4f60\u7684\u8ba8\u8bba\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"258\" height=\"258\" src=\"https:\/\/coderbee.net\/wp-content\/uploads\/2019\/01\/coderbee-note.jpg\" class=\"alignnone size-full wp-image-1707\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL \u5b89\u88c5\u540e\u9ed8\u8ba4\u7684\u5b57\u7b26\u96c6\u662f latin1\uff0c\u8fd9\u6837\u5728\u5904\u7406\u4e2d\u6587\u65f6\u5bb9\u6613\u51fa\u73b0\u4e71\u7801\u95ee\u9898 &hellip; <a href=\"https:\/\/coderbee.net\/index.php\/db\/20140112\/709\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[149,150],"_links":{"self":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/709"}],"collection":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/comments?post=709"}],"version-history":[{"count":2,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/709\/revisions"}],"predecessor-version":[{"id":711,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/posts\/709\/revisions\/711"}],"wp:attachment":[{"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/media?parent=709"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/categories?post=709"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderbee.net\/index.php\/wp-json\/wp\/v2\/tags?post=709"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}