MySQL command line import of file with UTF-8 encoding.
I am having trouble with an .sql file containing a backup of a database which will be used to restore the database daily.
The way I am executing the restore process is by using the mysql command (batch mode - linux shell):
mysql < origdata.sql
This works perfectly if the .sql file itself is encoded with default (ISO-????) character set, but when working with more exotic languages I have to use UTF-8. Saving the file in UTF-8 encoding is not working, since mysql doesn't know that it is UTF-8 and interprets it as default encoding, thus messing up a lot of forreign characters.
My question is, if there is a way to let mysql know that this file should be interpreted as UTF-8?
Either by
1) specifying the encoding on the command line
2) specifying the encoding within the file
3) specifying the encoding at filesystem level (I am not so clear here, but something like headers for http)
Note that this problem has nothing to do with the charset or collation of the database itself, nor with the database connection (these all work perfectly with UTF-8) only the command line import utility.
Please come forward if you know anything about this!
Jakob
Status:
Open Feb 16, 2007 - 02:17 AM
database, mysql, import, charset, encoding, UTF-8
1answer
Answer
Mar 15, 2007 - 01:32 AM
Thanks!
That command line parameter actually works - well, you have to use double dash (--) like this:
mysql -h host -u username -p password --default_character_set utf8 database < file.sql
Silly me hadn't tried it before because I'd read in a forum that it only applies to the connection and the database - not the file :-) Maybe that was true in a previous version of mysql...
Now it works!
Answer this question
Share Your Own Experience & Expertise
We look to ensure that every question is answered by the best people with relevant expertise and experience, the best answers include multiple perspectives. Do you have relevant expertise or experience to contribute your answer to any of these commonly asked questions?
Add New Comment