Friday, April 20, 2012

Mysql Change current database characterset

Assuming you have a database with default character set latin-1 & wish to convert it to utf-8, it is very simple to convert it without any external tool

1. Dump the database:

mysqldump -h localhost -u changeit -pchangeit --opt --compatible=mysql40 --default-character-set=latin1 database>database.sql

parameter –compatible=mysql40 is to dump the database without charset settings.

2. Create a database utf8 default:

CREATE DATABASE `database_new` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

3. Reimport the database

mysql -h localhost -u changeit -pchangeit --default-character-set=utf8 database_new < database.sql

Now you have received the utf8 character set database_new.

No comments:

Post a Comment