MySQL 错误 1115 (42000):未知字符集:'utf8mb4'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21911733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR 1115 (42000): Unknown character set: 'utf8mb4'
提问by saravanakumar
I have a MySQL dump, which I tried to restore with:
我有一个 MySQL 转储,我试图用它来恢复:
mysql -u"username" -p"password" --host="127.0.0.1" mysql_db < mysql_db
However, this threw an error:
但是,这引发了错误:
ERROR 1115 (42000) at line 3231: Unknown character set: 'utf8mb4'
This is lines 3231-3233:
这是第 3231-3233 行:
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
I am using MySQL 5.1.69. How can I solve this error?
我正在使用 MySQL 5.1.69。我该如何解决这个错误?
回答by Nanne
Your version does not support that character set, I believe it was 5.5.3
that introduced it. You should upgrade your mysql to the version you used to export this file.
您的版本不支持该字符集,我相信它是5.5.3
引入它的。您应该将 mysql 升级到用于导出此文件的版本。
The error is then quite clear: you set a certain character set in your code, but your mysql version does not support it, and therefore does not know about it.
错误很明显:您在代码中设置了某个字符集,但您的 mysql 版本不支持它,因此不知道它。
According to https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html:
根据https://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html:
utf8mb4 is a superset of utf8
utf8mb4 是 utf8 的超集
so maybe there is a chance you can just make it utf8, close your eyes and hope, but that would depend on your data, and I'd not recommend it.
所以也许你有机会让它成为 utf8,闭上你的眼睛和希望,但这取决于你的数据,我不推荐它。
回答by IT Vlogs
You can try:
你可以试试:
Open sql file by text editor find and replace all
通过文本编辑器打开sql文件查找并替换所有
utf8mb4 to utf8
Import again.
再次导入。
回答by wuxmedia
This can help:
这可以帮助:
mysqldump --compatible=mysql40 -u user -p DB > dumpfile.sql
PHPMyAdmin has the same MySQL compatibility mode in the 'expert' export options. Although that has on occasions done nothing.
PHPMyAdmin 在“专家”导出选项中具有相同的 MySQL 兼容模式。虽然这有时没有任何作用。
If you don't have access via the command line or via PHPMyAdmin then editing the
如果您无法通过命令行或 PHPMyAdmin 进行访问,则编辑
/*!50003 SET character_set_client = utf8mb4 */ ;
bit to read 'utf8'
only, is the way to go.
位只读'utf8'
,是要走的路。
回答by Kamran Ali
Just open your sql file with a text editor and search for 'utf8mb4' and replace with utf8.I hope it would work for you
只需使用文本编辑器打开您的 sql 文件并搜索 'utf8mb4' 并替换为 utf8。我希望它对您有用
回答by Nabeel Ahmed
I am answering the question - as I didn't find any of them complete. As nowadays Unknown character set: 'utf8mb4'is quite prevalent as lot of deployments have MySQL less then 5.5.3 (version in which utf8mb4 was added).
我正在回答这个问题 - 因为我没有发现它们中的任何一个是完整的。与现在一样, 未知字符集:'utf8mb4'非常流行,因为许多部署的 MySQL 都低于 5.5.3(添加了 utf8mb4 的版本)。
The error clearly states that you don't have utf8mb4
supported on your stage db server.
该错误明确指出utf8mb4
您的 stage db 服务器不支持。
Cause: probably locally you have MySQL
version 5.5.3 or greater, and on stage/hosted VPS you have MySQL server version less then 5.5.3
原因:您可能在本地拥有MySQL
5.5.3 或更高版本,而在舞台/托管 VPS 上,您的 MySQL 服务器版本低于 5.5.3
The utf8mb4
character sets was added in MySQL 5.5.3.
将utf8mb4
在MySQL 5.5.3添加字符集。
utf8mb4
was added because of a bug in MySQL'sutf8
character set. MySQL's handling of the utf8 character set only allows a maximum of 3 bytes for a single codepoint, which isn't enough to represent the entirety of Unicode (Maximum codepoint =0x10FFFF
). Because they didn't want to potentially break any stuff that relied on this buggy behaviour,utf8mb4
was added. Documentation here.
utf8mb4
由于 MySQLutf8
字符集的错误而添加。MySQL 对 utf8 字符集的处理只允许单个代码点最多 3 个字节,这不足以表示整个 Unicode(最大代码点 =0x10FFFF
)。因为他们不想潜在地破坏任何依赖于这种错误行为的东西,所以utf8mb4
添加了。文档在这里。
From SO answer:
从SO 回答:
Verification: To verify you can check the current character set and collation for the DB you're importing the dump from - How do I see what character set a MySQL database / table / column is?
验证:要验证您可以检查要从中导入转储的数据库的当前字符集和排序规则 -如何查看 MySQL 数据库/表/列是什么字符集?
Solution 1: Simply upgrade your MySQL server to 5.5.3 (at-least) - for next time be conscious about the version you use locally, for stage, and for prod, all must have to be same. A suggestion - in present the default character set should be utf8mb4.
解决方案 1:只需将您的 MySQL 服务器升级到 5.5.3(至少) - 下次请注意您在本地使用的版本,用于 stage 和 prod,所有版本都必须相同。一个建议 - 目前默认字符集应该是 utf8mb4。
Solution2 (not recommended): Convert the current character set to utf8, and then export the data - it'll load ok.
解决方案2(不推荐):将当前字符集转换为utf8,然后导出数据——加载正常。
回答by senthilkumar
Open your mysql file any edit tool
用任何编辑工具打开你的 mysql 文件
find
找
/*!40101 SET NAMES utf8mb4 */;
/*!40101 设置名称 utf8mb4 */;
change
改变
/*!40101 SET NAMES utf8 */;
/*!40101 设置名称 utf8 */;
Save and upload ur mysql.
保存并上传您的 mysql。
回答by Tung
As some suggested here, replacing utf8mb4
with utf8
will help you resolve the issue. IMHO, I used sed
to find and replace them to avoid losing data. In addition, opening a large file into any graphical editor is potential pain. My MySQL data grows up 2 GB. The ultimate command is
正如这里的一些建议,替换utf8mb4
withutf8
将帮助您解决问题。恕我直言,我曾经sed
查找并替换它们以避免丢失数据。此外,在任何图形编辑器中打开一个大文件是潜在的痛苦。我的 MySQL 数据增长了 2 GB。最终命令是
sed 's/utf8mb4_unicode_520_ci/utf8_unicode_ci/g' original-mysql-data.sql > updated-mysql-data.sql
sed 's/utf8mb4/utf8/g' original-mysql-data.sql > updated-mysql-data.sql
Done!
完毕!
回答by T.Todua
maybe whole database + tables + fields should have the same charset??!
也许整个数据库+表+字段应该具有相同的字符集??!
i.e.
IE
CREATE TABLE `politicas` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Nombre` varchar(250) CHARACTER SET utf8 NOT NULL,
-------------------------------------^here!!!!!!!!!!!
PRIMARY KEY (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
-------------------------------------------------^here!!!!!!!!!