{"id":292,"date":"2014-06-30T14:40:34","date_gmt":"2014-06-30T14:40:34","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=292"},"modified":"2014-06-30T14:40:34","modified_gmt":"2014-06-30T14:40:34","slug":"mysql%e5%ad%97%e7%ac%a6%e9%9b%86%e8%ae%be%e7%bd%ae%e7%9a%84%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/292.html","title":{"rendered":"MySQL\u5b57\u7b26\u96c6\u8bbe\u7f6e\u7684\u5b66\u4e60"},"content":{"rendered":"<pre class=\"lang:default decode:true\">use db_name;\nstatus;  #\u67e5\u770b\u6570\u636e\u5e93db_name\u7684\u7f16\u7801\nshow create database db_name;  #\u67e5\u770b\u6570\u636e\u5e93db_name\u7684\u7f16\u7801\nshow create table tb_name;  #\u67e5\u770b\u8868tb_name\u7684\u7f16\u7801\nstatus;  #\u67e5\u770b\u6570\u636e\u5e93\u670d\u52a1\u5668\u7aef\u548c\u5ba2\u6237\u7aef\u5b57\u7b26\u96c6\nshow variables like 'character%';<\/pre>\n<p>====<\/p>\n<p>\u67e5\u770b\u5b57\u7b26\u96c6\u8bbe\u7f6e\uff1a<\/p>\n<pre class=\"lang:default decode:true\">mysql&gt; show variables like 'collation_%';\nmysql&gt; show variables like 'char_%';<\/pre>\n<p>====<\/p>\n<pre class=\"lang:default decode:true\">mysql&gt; alter database db_a character set gbk;\n#\u4fee\u6539\u6570\u636e\u5e93\u7684\u5b57\u7b26\u96c6\u7f16\u7801\u65b9\u5f0f<\/pre>\n<p><span style=\"color: #ff0000;\"><strong>\u53c2\u8003\u94fe\u63a5<\/strong><\/span>\uff1a<a href=\"http:\/\/hi.baidu.com\/shunnarmeng\/item\/97108dafb4b93638030a4dee\" target=\"_blank\">\u6df1\u5165Mysql\u5b57\u7b26\u96c6\u8bbe\u7f6e<\/a><\/p>\n<p>MySQL\u5b57\u7b26\u96c6\u8bbe\u7f6e<br \/>\n\u2022 \u7cfb\u7edf\u53d8\u91cf\uff1a<br \/>\n\u2013 character_set_server\uff1a\u9ed8\u8ba4\u7684\u5185\u90e8\u64cd\u4f5c\u5b57\u7b26\u96c6<br \/>\n\u2013 character_set_client\uff1a\u5ba2\u6237\u7aef\u6765\u6e90\u6570\u636e\u4f7f\u7528\u7684\u5b57\u7b26\u96c6<br \/>\n\u2013 character_set_connection\uff1a\u8fde\u63a5\u5c42\u5b57\u7b26\u96c6<br \/>\n\u2013 character_set_results\uff1a\u67e5\u8be2\u7ed3\u679c\u5b57\u7b26\u96c6<br \/>\n\u2013 character_set_database\uff1a\u5f53\u524d\u9009\u4e2d\u6570\u636e\u5e93\u7684\u9ed8\u8ba4\u5b57\u7b26\u96c6<br \/>\n\u2013 character_set_system\uff1a\u7cfb\u7edf\u5143\u6570\u636e(\u5b57\u6bb5\u540d\u7b49)\u5b57\u7b26\u96c6<br \/>\n\u2013 \u8fd8\u6709\u4ee5collation_\u5f00\u5934\u7684\u540c\u4e0a\u9762\u5bf9\u5e94\u7684\u53d8\u91cf\uff0c\u7528\u6765\u63cf\u8ff0\u5b57\u7b26\u5e8f\u3002<\/p>\n<h5>\u5728my.cnf\u4e2d\u8bbe\u7f6eMySQL\u7684\u9ed8\u8ba4\u5b57\u7b26\u96c6\u7f16\u7801\u4e3autf-8<\/h5>\n<p>change mysql default character set to UTF8 in my.cnf?<br \/>\nTo set the default to UTF-8, you want to add the following to my.cnf<\/p>\n<pre class=\"lang:default decode:true\">[client]\ndefault-character-set=utf8\n\n[mysql]\ndefault-character-set=utf8\n\n[mysqld]\ncollation-server = utf8_unicode_ci\ninit-connect='SET NAMES utf8'\ncharacter-set-server = utf8<\/pre>\n<h6>\u539f\u6587\u94fe\u63a5\uff1a<\/h6>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/3513773\/change-mysql-default-character-set-to-utf8-in-my-cnf\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/3513773\/change-mysql-default-character-set-to-utf8-in-my-cnf<\/a><\/p>\n<hr \/>\n<p>\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u4e0d\u5728\u5b89\u88c5\u7684\u65f6\u5019\u6307\u5b9a\u7f16\u7801\u7684\u8bdd\uff0cMySQL\u4f1a\u9ed8\u8ba4\u4f7f\u7528latin1\u7684\u7f16\u7801\uff08\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48\u4e0d\u7528utf8\u4f5c\u4e3a\u9ed8\u8ba4\u7f16\u7801\uff1f\u56e0\u4e3aMySQL\u6700\u521d\u662f\u745e\u5178\u7684\u4e00\u5bb6\u516c\u53f8(MySQL AB)\u5f00\u53d1\u7684\uff0c\u6240\u4ee5\u9ed8\u8ba4\u7684\u5b57\u7b26\u96c6\u662flatin1\uff09\uff0c\u7136\u540e\uff0c\u5404\u79cd\u95ee\u9898\u5c31\u6765\u4e86\u2026\u2026<\/p>\n<p><strong>\u4e0d\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff0c\u53ea\u5c06\u5f53\u524d\u7684\u8868<\/strong><strong>\/<\/strong><strong>\u6570\u636e\u5e93\u5b58\u53d6\u8bbe\u7f6e\u4e3a<\/strong><strong>utf8<\/strong><\/p>\n<ol>\n<li>\u8bbe\u7f6e\u8868\u7684\u7f16\u7801\u4e3autf8\uff08\u53ef\u4ee5\u5148\u4f7f\u7528\uff1ashow create table tb_name; \u67e5\u770b\u5f53\u524d\u7f16\u7801\u683c\u5f0f\uff09<\/li>\n<li>\u8fde\u63a5\u7684\u65f6\u5019\u6307\u5b9a\u7f16\u7801\u4e3autf8<\/li>\n<li>\u6587\u4ef6\u7684\u683c\u5f0f\u3001\u5b57\u7b26\u4e32\u7684\u7f16\u7801\u4e3autf8<\/li>\n<\/ol>\n<p>\u53ef\u4ee5\u5728\u5efa\u7acbdatabase\u3001table\u7684\u65f6\u5019\u624b\u52a8\u6307\u5b9a\u7f16\u7801\u65b9\u5f0f\uff0c\u7136\u540e\u5728\u5b58\u5165\u6570\u636e\u7684\u65f6\u5019\u5c06\u8fde\u63a5\u7684\u65b9\u5f0f\u4e5f\u4fee\u6539\u4e3a\u5bf9\u5e94\u7684\u7f16\u7801\u65b9\u5f0f\u5373\u53ef\uff08\u53ef\u80fd\u4f1a\u9700\u8981\u5728\u663e\u793a\u4e4b\u524d\u5148\u6267\u884c\u547d\u4ee4\u201cset names\u00a0&#8216;utf8&#8217;;\u201d\u8fd9\u6837\u4e4b\u7c7b\u7684\uff09\uff0c\u4e4b\u540e\u5728\u663e\u793a\u7684\u65f6\u5019\u518d\u6267\u884c\u4e2a\u547d\u4ee4\u201cset names\u00a0&#8216;utf8&#8217;;\u201d\u5e94\u8be5\u5c31\u5dee\u4e0d\u591a\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>use db_name; status; #\u67e5\u770b\u6570\u636e\u5e93db_name\u7684\u7f16\u7801 show create datab [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[140,141,16],"class_list":["post-292","post","type-post","status-publish","format-standard","hentry","category-database","tag-charset","tag-my-cnf","tag-mysql"],"views":3584,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=292"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/292\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}