mysql dump 乱码问题

将utf8编码的数据库使用mysqldump.exe来导出,得到的却是乱码

明明设置了--default-character-set=utf8 任然如此,网上搜了些文章,例如 http://blog.derjohng.com/2006/01/18/backup-mysql-utf8-data/

说的是改为--default-character-set=latin1,我试了一下,还是乱码。莫名其妙,想了想试试如下的命令

"D:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe" --user=root --password=root --default-character-set=gbk --skip-opt --add-drop-table --set-charset --dump-date --result-file=data.sql test

这样导出的结果编码才是正确的。(注意不要丢掉--skip-opt 选项)

问题是解决了,我还是莫名其妙。

明明设置的是utf8,数据库my.ini里面默认也是utf8,哪里搞出个gbk来了?

看官方文档,有这么一句话:

http://dev.mysql.com/doc/refman/5.1/en/charset-configuration.html

when character_set_system differs from character_set_server or character_set_client, and you input characters manually (as database object identifiers, column values, or both), these may be displayed incorrectly in output from the client or the output itself may be formatted incorrectly. In such cases, starting the mysql client with --default-character-set=system_character_set—that is, setting the client character set to match the system character set—should fix the problem.

似乎是要匹配文件系统字符集,也就是你的操作系统字符集。


Total views.

© 2013 - 2018. All rights reserved.

Powered by Hydejack v6.6.1