Search code examples
mysqlutf-8collationalter

How to change all the tables in my database to UTF8 character set?


My database is not in UTF8, and I'd like to convert all the tables to UTF8, how can I do this?


Solution

  • mysqldump --user=username --password=password --default-character-set=latin1 --skip-set-charset dbname > dump.sql
    sed -r 's/latin1/utf8/g' dump.sql > dump_utf.sql
    mysql --user=username --password=password --execute="DROP DATABASE dbname; CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;"
    mysql --user=username --password=password --default-character-set=utf8 dbname < dump_utf.sql