{"id":2541,"date":"2013-07-18T01:56:56","date_gmt":"2013-07-18T01:56:56","guid":{"rendered":"http:\/\/www.withdata.com\/ad\/?p=2541"},"modified":"2017-04-20T11:09:11","modified_gmt":"2017-04-20T11:09:11","slug":"change-mysql-table-character-set-from-latin1-to-utf8","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/mysql\/change-mysql-table-character-set-from-latin1-to-utf8.html","title":{"rendered":"Change MySQL table character set from latin1 to utf8"},"content":{"rendered":"<p>I have a table &#8220;t_user&#8221;, it&#8217;s character set is &#8220;latin1&#8221; when create it, and I want to save some unicode text at field &#8220;username&#8221;, but when I saved, the data is &#8220;????&#8221;, so I need to change character set from &#8220;latin1&#8221; to &#8220;utf8&#8221;.<\/p>\n<p>I use<\/p>\n<pre>ALTER TABLE `t_user` CHARSET=utf8;<\/pre>\n<p>then I saved unicode data again, but still &#8220;????&#8221;.<\/p>\n<p>I found that the character set of the field &#8220;username&#8221; is still &#8220;latin1&#8221;, so I droped field &#8220;username&#8221;,<\/p>\n<pre>ALTER TABLE `t_user` DROP COLUMN `username`;<\/pre>\n<p>and then create it again,<\/p>\n<pre>ALTER TABLE `t_user`\r\nADD COLUMN `username` VARCHAR(20) NULL;<\/pre>\n<p>the character set of the field &#8220;username&#8221; is &#8220;utf8&#8221; now, and the unicode data was saved correctly.<\/p>\n<p>Some MySQL tools you can try: <a href=\"https:\/\/www.withdata.com\/mysql\/\"> https:\/\/www.withdata.com\/mysql\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a table &#8220;t_user&#8221;, it&#8217;s character set is &#8220;latin1&#8221; when create it, and I want to save some unicode text at field &#8220;username&#8221;, but when I saved, the data is &#8220;????&#8221;, so I need to change character set from &#8220;latin1&#8221; to &#8220;utf8&#8221;. I use ALTER TABLE `t_user` CHARSET=utf8; then I saved unicode data again, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[420,419,1323],"class_list":["post-2541","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-change-mysql-table-charater-set","tag-character-set","tag-mysql"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/2541","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=2541"}],"version-history":[{"count":4,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/2541\/revisions"}],"predecessor-version":[{"id":6459,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/2541\/revisions\/6459"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=2541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=2541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=2541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}