{"id":1339,"date":"2017-10-16T12:49:43","date_gmt":"2017-10-16T03:49:43","guid":{"rendered":"https:\/\/www.dogrow.net\/linux\/?p=1339"},"modified":"2023-12-29T01:29:52","modified_gmt":"2023-12-28T16:29:52","slug":"blog68","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/linux\/blog68\/","title":{"rendered":"(68)\u3010DB\u3011MySQL\u306e\u6587\u5b57\u30b3\u30fc\u30c9\u3092UTF-8\u304b\u3089UTF-8 MB4\u306b\u5909\u66f4\u3059\u308b\u3002"},"content":{"rendered":"<h1 class=\"my_h\">(1) \u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>\u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u30fc\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b MySQL\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u304c 5.1 \u304b\u3089 5.7 \u306b\u4e0a\u304c\u3063\u305f\u3002<br \/>\n\u3053\u308c\u306b\u3088\u308a\u30014\u30d0\u30a4\u30c8UTF8\u6587\u5b57\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3002<br \/>\n\u3059\u306a\u308f\u3061\u7d75\u6587\u5b57\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3002<br \/>\n\u3053\u308c\u3092\u4f7f\u3044\u305f\u3044\uff01<\/p>\n<p>\u3067\u3082\u3001\u81ea\u52d5\u7684\u306b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092 4\u30d0\u30a4\u30c8\u5bfe\u5fdcUTF-8 \u306b\u5909\u3048\u3066\u304f\u308c\u308b\u308f\u3051\u3067\u306f\u306a\u3044\u306e\u3067\u3001\u81ea\u5206\u3067\u305b\u3063\u305b\u3068\u5909\u66f4\u3059\u308b\u3002 <\/p>\n<h1 class=\"my_h\">(2) \u5909\u66f4\u4f5c\u696d<\/h1>\n<p>\u4ee5\u4e0b\u3001\u5099\u5fd8\u9332\u3068\u3057\u3066\u624b\u9806\u3092\u8a18\u3057\u3066\u304a\u304f\u3002<\/p>\n<p><span class=\"my_fc_deeppink my_fw_bold\">mysql<\/span>\u30b3\u30de\u30f3\u30c9\u306e\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u3053\u3061\u3089\u306e\u516c\u5f0f\u30b5\u30a4\u30c8\u306b\u8a73\u3057\u304f\u66f8\u304b\u308c\u3066\u3044\u308b\u3002<br \/>\n<a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/mysql-command-options.html\" target=\"_blank\" rel=\"noopener\">https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/mysql-command-options.html<\/a><\/p>\n<p>\u4eca\u56de\u4f7f\u7528\u3057\u305f\u30aa\u30d7\u30b7\u30e7\u30f3\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<br \/>\n<table class=\"my_tbl_simple\">\n<tr><td><span class=\"my_fc_deeppinkB\">&#8211;user=<\/span>user_name<\/td><td><span class=\"my_fc_deeppinkB\">-u<\/span> user_name<\/td><td>\u30e6\u30fc\u30b6\u30fc\u540d<\/td><\/tr><tr><td><span class=\"my_fc_deeppinkB\">&#8211;database=<\/span>db_name<\/td><td><span class=\"my_fc_deeppinkB\">-D<\/span> db_name<\/td><td>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u540d<\/td><\/tr><tr><td><span class=\"my_fc_deeppinkB\">&#8211;password=<\/span>password<\/td><td><span class=\"my_fc_deeppinkB\">-p<\/span>password<\/td><td>\u30d1\u30b9\u30ef\u30fc\u30c9 <span class=\"my_fc_crimson\">\u203b<b>p<\/b>\u306e\u5f8c\u306e\u7a7a\u767d\u6587\u5b57\u306fNG<\/span><\/td><\/tr><tr><td><span class=\"my_fc_deeppinkB\">&#8211;execute=<\/span>statement<\/td><td><span class=\"my_fc_deeppinkB\">-e<\/span> statement<\/td><td>SQL\u30b3\u30de\u30f3\u30c9<\/td><\/tr>\n<\/table><\/p>\n<h3 class=\"my_h\">1) \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u6587\u5b57\u30b3\u30fc\u30c9\u3092 UTF8 \u304b\u3089 UTF8MB4 \u306b\u5909\u66f4\u3059\u308b\u3002<\/h3>\n<p>\u307e\u305a\u306f DB\u306e character set \u3092\u5909\u66f4\u3059\u308b\u3002<\/p>\n<pre class=\"brush: bash; class-name: &#039;my_border_1px&#039;; title: ; notranslate\" title=\"\">\r\nDATABASE=xxxxxx\r\nUSERNAME=yyyyyy\r\nPASSWORD=zzzzzz\r\n\r\nSQLCMD=&quot;ALTER DATABASE ${DATABASE} CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;&quot; \r\nSHOWDH=&quot;show variables like \\&quot;chara%\\&quot;;&quot; \r\n\r\nmysql -u $USERNAME -D $DATABASE -p$PASSWORD -e &quot;$SHOWDH&quot; \r\nmysql -u $USERNAME -D $DATABASE -p$PASSWORD -e &quot;$SQLCMD&quot; \r\nmysql -u $USERNAME -D $DATABASE -p$PASSWORD -e &quot;$SHOWDH&quot; \r\n<\/pre>\n<p>\u7d9a\u3051\u3066\u30c6\u30fc\u30d6\u30eb\u304a\u3088\u3073\u30ab\u30e9\u30e0\u306e character set \u3092\u5909\u66f4\u3059\u308b\u3002<br \/>\n\u30c0\u30f3\u30d7\u51fa\u529b\u3057\u3066\u4e00\u6c17\u306b\u7f6e\u63db\u30fb\u5909\u66f4\u3057\u3001\u30ea\u30b9\u30c8\u30a2\u3059\u308b\u3002<\/p>\n<pre class=\"brush: bash; class-name: &#039;my_border_1px&#039;; title: ; notranslate\" title=\"\">\r\nDUMP1=mydb.dump\r\nDUMP2=mydb_new.dump\r\n\/usr\/local\/mysql\/bin\/mysqldump $DATABASE -h localhost -u $USERNAME -p$PASSWORD -e --single-transaction &gt; $DUMP1\r\n\r\nsed -e &quot;s\/CHARSET=utf8\/CHARSET=utf8mb4\/g&quot; $DUMP1 &gt; $DUMP2\r\n\r\nmysql -u $USERNAME -p$PASSWORD  -D$DATABASE &lt; $DUMP2\r\n<\/pre>\n<h3 class=\"my_h\">2) \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u4e2d\u306e\u6587\u5b57\u30b3\u30fc\u30c9\u6307\u5b9a\u3092\u5909\u66f4\u3059\u308b\u3002<\/h3>\n<pre class=\"brush: php; class-name: &#039;my_border_1px&#039;; title: ; notranslate\" title=\"\">\r\ndb = new mysqli(&quot;localhost&quot;, USER, PW, NAME);\r\ndb-&gt;set_charset(&quot;utf8mb4&quot;)\r\n<\/pre>\n<p>\u3042\u3068\u3067\u6e05\u66f8\u3057\u3088\u3046\u3002<\/p>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>(1) \u3084\u308a\u305f\u3044\u3053\u3068 \u30ec\u30f3\u30bf\u30eb\u30b5\u30fc\u30d0\u30fc\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u308b MySQL\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u304c 5.1 \u304b\u3089 5.7 \u306b\u4e0a\u304c\u3063\u305f\u3002 \u3053\u308c\u306b\u3088\u308a\u30014\u30d0\u30a4\u30c8UTF8\u6587\u5b57\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3002 \u3059\u306a\u308f\u3061\u7d75\u6587\u5b57\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u3002 \u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/linux\/blog68\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[125,80],"tags":[],"class_list":["post-1339","post","type-post","status-publish","format-standard","hentry","category-db","category-mysql"],"views":5634,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/linux\/wp-json\/wp\/v2\/posts\/1339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/linux\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/linux\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/linux\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/linux\/wp-json\/wp\/v2\/comments?post=1339"}],"version-history":[{"count":13,"href":"https:\/\/www.dogrow.net\/linux\/wp-json\/wp\/v2\/posts\/1339\/revisions"}],"predecessor-version":[{"id":3655,"href":"https:\/\/www.dogrow.net\/linux\/wp-json\/wp\/v2\/posts\/1339\/revisions\/3655"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/linux\/wp-json\/wp\/v2\/media?parent=1339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/linux\/wp-json\/wp\/v2\/categories?post=1339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/linux\/wp-json\/wp\/v2\/tags?post=1339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}