MySql tip #2 Taking backup ensuring multi byte characters does not become garbage

If you have multi byte data in your tables its important to take backup in utf8 which can be done using the command below:

mysqldump -u root --default-character-set=utf8 DB_NAME | gzip > DB_NAME-`date +%Y%m%d%H%M`.sql.gz

The date parameter simply appends date/time to the backup.

In order to restore the backup taken above use following command

gunzip < FILE_NAME.sql.gz | mysql --default-character-set=utf8 -u root DB_NAME

This will ensure that db is back up without affecting multi byte data.

Leave a Reply