MySQL #1115 - 未知字符集:'utf8mb4'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33036213/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:19:10  来源:igfitidea点击:

#1115 - Unknown character set: 'utf8mb4'

mysqlutf-8character-encodingutf8mb4

提问by Dev.Wol

I have a local webserver running on my pc to which I use for local development. I'm now at the stage of exporting the database and importing onto my hosted VPS.

我的电脑上运行着一个本地网络服务器,用于本地开发。我现在正处于导出数据库并导入到我托管的 VPS 的阶段。

When exporting then importing I get the following error!

导出然后导入时出现以下错误!

1115 - Unknown character set: 'utf8mb4'

1115 - 未知字符集:'utf8mb4'

Can somebody point me in the right direction?

有人可以指出我正确的方向吗?

回答by Nabeel Ahmed

The error clearly states that you don't have utf8mb4supported on your stage db server.

该错误明确指出utf8mb4您的 stage db 服务器不支持。

Cause: probably locally you have MySQLversion 5.5.3or greater, and on stage/hosted VPS you have MySQLserver 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 中添加的。

utf8mb4was added because of a bug in MySQL's utf8character set. MySQL's handling of the utf8character 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, utf8mb4was added. Documentation here.

utf8mb4由于 MySQLutf8字符集的错误而添加。MySQL 对utf8字符集的处理只允许单个代码点最多 3 个字节,这不足以表示整个 Unicode(最大代码点 = 0x10FFFF)。因为他们不想潜在地破坏任何依赖于这种错误行为的东西,所以utf8mb4添加了。文档在这里



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.



Solution 2(not recommended): Convert the current character set to utf8, and then export the data - it'll load ok.

解决方案 2(不推荐):将当前字符集转换为utf8,然后导出数据 - 加载正常。

回答by user2719572

Open sql file by text editor find and replace all

通过文本编辑器打开sql文件查找并替换所有

utf8mb4 to utf8

Import again.

再次导入。

回答by Jan

This helped me

这帮助了我

ALTER TABLE your_table_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

回答by Grzegorz Adam Kowalski

Sometimes I get similar problems while using HeidiSQL which by default exports in utf8mb4 character encoding. Not all MySQL installations support this encoding and importing such data leads to similar error messages. My workaround then is to export data using phpMyAdmin, which exports in utf8. There are problably other tools and possible ways like manually editing dump file, converting it from utf8mb4 to utf8 (if needed) and changing SET NAMES utf8mb4to SET NAMES utf8. Utf8mb4 is a superset of utf8, so if you're absolutely sure, that your data is just utf8, then you can simply change SET NAMESin dump file to utf8.

有时我在使用 HeidiSQL 时会遇到类似的问题,默认情况下它以 utf8mb4 字符编码导出。并非所有 MySQL 安装都支持这种编码,导入此类数据会导致类似的错误消息。我的解决方法是使用 phpMyAdmin 导出数据,它以 utf8 格式导出。可能还有其他工具和可能的方法,例如手动编辑转储文件,将其从 utf8mb4 转换为 utf8(如果需要)并更改SET NAMES utf8mb4SET NAMES utf8. utf8mb4 是 utf8 的超集,因此如果您绝对确定您的数据只是 utf8,那么您只需将SET NAMES转储文件更改为utf8.