howto:mysql-latin1-to-utf8
This is an old revision of the document!
Convert latin1 MySQL db to utf8
Export db, change charset, convert and import again:
mysqldump -u username -p --add-drop-table database-name | replace CHARSET=latin1 CHARSET=utf8 | iconv -f latin1 -t utf8 | mysql -u username -p -D database-name
For websites, ensure that the header and document type are set correctly:
header('Content-Type: text/html; charset=UTF8');
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
php.ini should have:
; PHP's built-in default is text/html default_mimetype = "text/html" default_charset = "utf-8"
my.cnf should have:
[client] default-character-set=utf8 [myslqd] skip-character-set-client-handshake collation_server=utf8_unicode_ci character_set_server = utf8
alternatively, in php scripts set:
@mysql_query("SET NAMES utf8") or die ("Could not set character set to UTF8: ".mysql_error());
howto/mysql-latin1-to-utf8.1648221784.txt.gz · Last modified: (external edit)