Reputation: 4630
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
Reputation: 125945
( Upgrading to an answer )
As documented under mysqldump
— A Database Backup Program:
--default-character-set=charset_name
Use
charset_name
as the default character set. See Section 10.5, “Character Set Configuration”. If no character set is specified,mysqldump
usesutf8
, and earlier versions uselatin1
.
[ deletia ]
Add
SET NAMES default_character_set
to the output. This option is enabled by default. To suppress theSET 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