{"id":390,"date":"2014-01-17T11:06:24","date_gmt":"2014-01-17T03:06:24","guid":{"rendered":"http:\/\/www.cnmiss.cn\/?p=390"},"modified":"2014-01-17T11:06:24","modified_gmt":"2014-01-17T03:06:24","slug":"mysql-utf8mb4-%e5%ad%97%e7%ac%a6%e9%9b%86%ef%bc%9a%e6%94%af%e6%8c%81-emoji-%e8%a1%a8%e6%83%85%e7%ac%a6%e5%8f%b7","status":"publish","type":"post","link":"https:\/\/www.cnmiss.cn\/?p=390","title":{"rendered":"MySQL utf8mb4 \u5b57\u7b26\u96c6\uff1a\u652f\u6301 emoji \u8868\u60c5\u7b26\u53f7"},"content":{"rendered":"<p>\u3220 \u5e8f\u8a00<\/p>\n<p>\u4e3a\u4e86\u5e94\u5bf9\u65e0\u7ebf\u4e92\u8054\u7f51\u7684\u673a\u9047\u548c\u6311\u6218\u3001\u907f\u514d emoji \u8868\u60c5\u7b26\u53f7\u5e26\u6765\u7684\u95ee\u9898\u3001<br \/>\n\u6d89\u53ca\u65e0\u7ebf\u76f8\u5173\u7684 MySQL \u6570\u636e\u5e93\u5efa\u8bae\u90fd\u63d0\u524d\u91c7\u7528 utf8mb4 \u5b57\u7b26\u96c6<br \/>\n\u8fd9\u5fc5\u987b\u8981\u4f5c\u4e3a\u79fb\u52a8\u4e92\u8054\u7f51\u884c\u4e1a\u7684\u4e00\u4e2a\u6280\u672f\u9009\u578b\u7684\u8981\u70b9<\/p>\n<p>\u3221 \u9650\u5236<\/p>\n<p>\u9700\u8981 &gt;= MySQL 5.5.3\u7248\u672c\u3001\u4ece\u5e93\u4e5f\u5fc5\u987b\u662f5.5\u7684\u4e86\u3001\u4f4e\u7248\u672c\u4e0d\u652f\u6301\u8fd9\u4e2a\u5b57\u7b26\u96c6\u3001\u590d\u5236\u62a5\u9519<\/p>\n<p>\u3222 \u7b80\u8981\u6b65\u9aa4<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u672a\u5347\u7ea7\u5230 5.5.3 \u7684\u914d\u7f6e\u6b65\u9aa4\uff1a<\/p>\n<p>\u2460 \u5907\u4efd\u6570\u636e\u5e93<br \/>\n\u2461 \u5347\u7ea7 MySQL Server \u5230 v5.5.3+<br \/>\n\u2462 \u4fee\u6539 database\u3001table\u548ccolumn\u5b57\u7b26\u96c6<\/p>\n<pre># For each database:ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;\r\n# For each table:ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\r\n# For each column:ALTER TABLE table_name CHANGE column_name column_name VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\r\n# (Don\u2019t blindly copy-paste this! The exact statement depends on the column type, maximum length, and other properties. The above line is just an example for a `VARCHAR` column.)<\/pre>\n<p>\u2463 \u4fee\u6539 my.cnf<\/p>\n<pre>[client]  \r\ndefault-character-set = utf8mb4  \r\n\r\n[mysql]  \r\ndefault-character-set = utf8mb4  \r\n\r\n[mysqld]  \r\ncharacter-set-client-handshake = FALSE  \r\ncharacter-set-server = utf8mb4  \r\ncollation-server = utf8mb4_unicode_ci  \r\ninit_connect='SET NAMES utf8mb4'<\/pre>\n<p>\u2464 \u91cd\u542f MySQL Server\u3001\u68c0\u67e5\u5b57\u7b26\u96c6<\/p>\n<pre>mysql&gt; SHOW VARIABLES WHERE Variable_name LIKE 'character\\_set\\_%' OR Variable_name LIKE 'collation%';  \r\n+--------------------------+--------------------+  \r\n| Variable_name            | Value              |  \r\n+--------------------------+--------------------+  \r\n| character_set_client     | utf8mb4            |  \r\n| character_set_connection | utf8mb4            |  \r\n| character_set_database   | utf8mb4            |  \r\n| character_set_filesystem | binary             |  \r\n| character_set_results    | utf8mb4            |  \r\n| character_set_server     | utf8mb4            |  \r\n| character_set_system     | utf8               |  \r\n| collation_connection     | utf8mb4_unicode_ci |  \r\n| collation_database       | utf8mb4_unicode_ci |  \r\n| collation_server         | utf8mb4_unicode_ci |  \r\n+--------------------------+--------------------+  \r\nrows in set (0.00 sec)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u3220 \u5e8f\u8a00 \u4e3a\u4e86\u5e94\u5bf9\u65e0\u7ebf\u4e92\u8054\u7f51\u7684\u673a\u9047\u548c\u6311\u6218\u3001\u907f\u514d emoji \u8868\u60c5\u7b26\u53f7\u5e26\u6765\u7684\u95ee\u9898\u3001 &hellip; <a href=\"https:\/\/www.cnmiss.cn\/?p=390\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[57,24,58],"class_list":["post-390","post","type-post","status-publish","format-standard","hentry","category-xxbj","tag-emoji","tag-mysql","tag-utf8mb4"],"_links":{"self":[{"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=\/wp\/v2\/posts\/390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=390"}],"version-history":[{"count":0,"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=\/wp\/v2\/posts\/390\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}