I'm using the following command to export data from my database to csv:
mysqldump -u root -p -T/home/xxx/stock_dump -t --fields-terminated-by=";" products stock
But the database is in UTF-8 and this command exports UTF-8 characters incorrectly, e.g.
ŻYWIEC ZDRÓJ is ĂÂťYWIEC ZDRĂâJ
How do I export it in the correct UTF-8 format?
Adding --default-character-set=utf8 did not help at all.
Or if it is not possible, how do I postprocess it the easiest way? Can iconv do anything about it?
mysqldump produces UTF-8 encoded dumps unless told otherwise (or unless you use a really, really old version of mysqldump -- anyways, your correct using of --default-character-set=utf8 settles it).
Either your text editor is not recognizing UTF-8 correctly, or the data in the database is already wrongly encoded.
Related
I've got some problem in one of the TYPO3 Polish sites with character encoding. There was no setDBinit=SET NAMES utf8; parameter set in configuration.
Everything works okay (frontend & backend) but the export from the database. All international characters are corrupted when I search database via PhpMyAdmin or try to export database with data.
The official page http://wiki.typo3.org/UTF-8_support#SET_NAMES_utf8.3B says:
Without SET NAMES utf8; your TYPO3 UTF-8 setup might work, but chances are that database content entered after the conversion to UTF-8 has each international character stored as two separate, garbled latin1 chars.
If you check your database using phpMyAdmin and find umlauts in new content being shown as two garbled characters, this is the case. If this happens to you, you cannot just add the above statement any more. Your output for the new content will be broken. Instead you have to correct the newly added special chars first. This is done most easily by just deleting the content, setting the option as described above and re-entering it.
Is there any other way to repair corrupted characters? There is a lot of content to edit now...
I tried almost every combination of export encoding and converting to another encoding and so on and so far I failed.
You can try mysqldump to convert from ISO-8859-1 to utf-8:
mysqldump --user=username --password=password --default-character-set=latin1 --skip-set-charset dbname > dump.sql
chgrep latin1 utf8 dump.sql (or when you prefer sed -i "" 's/latin1/utf8/g' dump.sql)
mysql --user=username --password=password --execute="DROP DATABASE dbname; CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;"
mysql --user=username --password=password --default-character-set=utf8 dbname < dump.sql
I have a mysql dump what contains ascii characters like überprüft. My problem is like I can not make another dump and I have been searching on the net for a solution but every suggestions would involve another dump set it up to utf-8. Is there a way to convert a dump file.
Is the entire dump encoded like that, that is, in UTF-8? In that case you can simply set the encoding when you import the dump.
If you use the mysql command line client to import the dump, use the --default-character-set command line switch when importing, for example:
> mysql -u user --default-character-set=utf8 < dump.sql
How to change encoding of the mysql dump files?
When I run mysqldump command it creates file encoded in ANSI. How to change it to utf-8? I have also tried to do this:
mysqldump --user=user1--password=pas1 --default-character-set=utf8 mydb1 mytbl1 > e:\1.sql
According to this forum thread, the culprit is the > filename redirection on Windows, which seems to have trouble with UTF-8 characters.
Try using the --result-file parameter instead.
when I try and run:
mysql -u myUser -pPassword -D myDatabase -h myHost < toInsert.sql
from my ubuntu desktop where myHost is a remote Red Hat server and toInsert.sql contains ’ they show up as ’
How can I resolve this?
Note! ’ is NOT the same as '
When I run toInsert.sql from a windows machine with a mysql gui client I do not have this problem.
Thanks
--default-character-set=utf8 has fixed it
so
mysql -u myUser -pPassword -D myDatabase -h myHost --default-character-set=utf8 < toInsert.sql
thanks for the help!
Sounds like you've got code that's confused about encodings. Define what the encoding of the string data in the database is (I recommend UTF-8, but anything will work so long as you're consistent) and then make sure that all the tools you use with it realize that fact.
And “’” is a “’” when the UTF-8 data bytes are reinterpreted as ISO 8859-1.
There are two places this problem could be:
First, you need to check that the encoding on everything in your database is UTF-8.
If that doesn't fix it, then your database might be correct, but your console is unable to display UTF-8 characters. Pipe the output of a query into a file and view it in something that can display UTF-8 characters and see if it looks correct. If it looks correct, then the problem is your terminal.
php code:
exec('mysqldump --opt --compress --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASS.' '.DB_NAME.' > file.sql');
some characters are not being exported as they are in the DB. For example "ñ" becomes "ñ" -- am i missing a parameter in the mysqldump instruction? BTW, the DB is utf8. thanks!
See this question: How to keep special characters when running ./mysqldump?
Try adding the switch: --default-character-set=UTF8