[英]How to get mysqldump to export a database in the right encoding and collation?
I'm having a problem with the encoding when dumping a database using mysqldump
.使用
mysqldump
转储数据库时,我遇到了编码问题。
The issue is that the file being generated is breaking non-ASCII characters (for ex. german and spanish characters).问题是正在生成的文件破坏了非 ASCII 字符(例如德语和西班牙语字符)。 The data in the DB is right, but it is exported wrong.
数据库中的数据是正确的,但导出错误。
I have tried the following:我尝试了以下方法:
--default-character-set
to utf8, utf8mb4, and latin1 (the last option because although the tables are using utf8_general_ci collation, the database itself is set to latin1, I don't know why).--default-character-set
为 utf8、utf8mb4 和 latin1(最后一个选项,因为虽然表使用 utf8_general_ci 排序规则,但数据库本身设置为 latin1,我不知道为什么)。 Weirdly enough, the output differs in filesize, but the content (specially the problematic characters) shows the same issue in all three cases. An example of the sentence I'm running:我正在运行的句子示例:
mysqldump --default-character-set=utf8mb4 --no-tablespaces -u database_user -p database_name > /home/username/database_name-utf8mb4-20220712.sql
No errors appear neither during the export nor during the import in the new server.在导出过程中和在新服务器中导入过程中都不会出现错误。 Everything seems to run smooth, but the character encoding is messed up, so something isn't OK.
一切似乎都很顺利,但是字符编码搞砸了,所以有些事情不妙。
Any support is much appreciated.非常感谢任何支持。 Thank you!
谢谢!
but the character encoding is messed up
但是字符编码搞砸了
Give us an example.给我们一个例子。 Include a hex dump of a small portion of the file where garbage shows up.
包括文件中出现垃圾的一小部分的十六进制转储。
It is likely that the original data was either in character set utf8 or latin1, but the dumping and/or reloading specified the wrong character set.原始数据可能是字符集 utf8 或 latin1,但转储和/或重新加载指定了错误的字符集。 Please provide more details of the dump and load.
请提供转储和加载的更多详细信息。
Also see: Trouble with UTF-8 characters;另请参阅: UTF-8 字符问题; what I see is not what I stored
我看到的不是我存储的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.