Anonymous
Anonymous

Reputation: 4630

DB upload in mysql - loses UTF characters

I'm frequently updating my db on the server, and I run the following line from the command line:

mysqldump -u root --password=mypass mydb|mysql -h mysite.cc -u remotusr --password=remotpsw remotdb

The problem is that it loses the UTF characters along the way.

How can I keep the utf chars in cmd, or what is a better practice doing this?

Upvotes: 0

Views: 120

Answers (1)

eggyal
eggyal

Reputation: 125945

( Upgrading to an answer )

As documented under mysqldump — A Database Backup Program:

[ deletia ]

  • --set-charset

    Add SET NAMES default_character_set to the output. This option is enabled by default. To suppress the SET NAMES statement, use --skip-set-charset.

Therefore, unless you have settings in an option file which are overriding these defaults (you can specify --no-defaults to ensure they are not), the output from mysqldump should be more than capable of being redirected to another mysql session without loss of Unicode characters.

Instead, the conversion to a smaller character set appears to be occurring on retrieving & displaying your data from the new database. Since you are using PHP's Original MySQL API for this purpose, despite the warning in the introduction to its manual chapter (below), you should use mysql_set_charset() to set the connection character set.

This extension is not recommended for writing new code. Instead, either the mysqli or PDO_MySQL extension should be used. See also the MySQL API Overview for further help while choosing a MySQL API.

Upvotes: 1

Related Questions