Posted over 8 years ago. Visible to the public.

Dumping and importing from/to MySQL in an UTF-8 safe way

In a nutshell: to avoid your shell character set from messing with imports, use -r to export and SOURCE when importing.

Dumping safely

Copy
# Do not do this, since it might screw up encoding mysqldump -uroot -p database > utf8.dump # this is bad

Better do:

Copy
mysqldump -uroot -p database -r utf8.dump

Note that when your MySQL server is not set to UTF-8 you need to do mysqldump --default-character-set=latin1 (!) to get a correctly encoded dump. In that case you will also need to remove the SET NAMES='latin1' comment at the top of the dump, so the target machine won't change its UTF-8 charset when sourcing.

If you only want to dump the structure without data, use

Copy
mysqldump -uroot -p --no-data database -r utf8.dump

Importing a dump safely

Copy
# Do not do this, since it might screw up encoding mysql -u username -p database < dump_file # this is bad

Better do:

Copy
mysql -uroot -p --default-character-set=utf8 database mysql> SET names 'utf8' mysql> SOURCE utf8.dump

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Henning Koch
Last edit:
over 1 year ago
by Dominik Schöler
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more