如何在mysql中插入utf-8 mb4字符(ios5中的表情符号)?

发布于 2024-12-11 02:40:03 字数 890 浏览 1 评论 0原文

我使用的是mysql 5.5.10,它的字符集是

| character_set_client     | utf8mb4                    |
| character_set_connection | utf8mb4                    |
| character_set_database   | utf8mb4                    |
| character_set_filesystem | binary                     |
| character_set_results    | utf8mb4                    |
| character_set_server     | utf8mb4                    |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
| collation_connection     | utf8mb4_general_ci         |
| collation_database       | utf8mb4_general_ci         |
| collation_server         | utf8mb4_general_ci         |

我为iOS5的表情符号从utf8更改为utf8mb4。它们由 4 字节代码表示。

但当我插入 3 个笑脸表情符号时,“???”是在mysql中。

它们是 3F 3F 3F(十六进制)。

我可以很好地存储iOS4的表情符号,但不能存储iOS5的表情符号。

如何存储iOS5的表情符号?

请帮我。

I am using mysql 5.5.10, and its character_sets are

| character_set_client     | utf8mb4                    |
| character_set_connection | utf8mb4                    |
| character_set_database   | utf8mb4                    |
| character_set_filesystem | binary                     |
| character_set_results    | utf8mb4                    |
| character_set_server     | utf8mb4                    |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
| collation_connection     | utf8mb4_general_ci         |
| collation_database       | utf8mb4_general_ci         |
| collation_server         | utf8mb4_general_ci         |

I changed utf8mb4 from utf8 for iOS5's emoji. They are represented by 4byte code.

But when I inserted 3 smiley emojis, '???' is in mysql.

They are 3F 3F 3F (Hex).

I can store iOS4's emojis well, but not iOS5's.

How could I store iOS5's emojis?

Please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泅渡 2024-12-18 02:40:03

4 字节 Unicode 字符尚未广泛使用,因此并非每个应用程序都完全支持它们。如果配置正确,MySQL 5.5 可以正常使用 4 字节字符 - 检查您的其他组件是否也可以使用它们。

这里还有一些其他需要检查的事情:

  • 除了设置客户端和文本字段之外,还要确保所有表的默认字符集和文本字段都转换为 utf8mb4。服务器字符集,例如
    ALTER TABLE mytable charset=utf8mb4、修改列 textfield1 VARCHAR(255) 字符集 utf8mb4、修改列 textfield2 VARCHAR(255) 字符集 utf8mb4; 等等。

    如果您的数据已经采用 utf8 字符集,那么它应该可以毫无问题地转换为 utf8mb4。一如既往,在尝试之前备份数据!

  • 还要确保您的应用程序层将其数据库连接的字符集设置为 utf8mb4。仔细检查这确实发生了 – 如果您运行的是所选框架的 mysql 客户端库的旧版本,它可能没有使用 utf8mb4 支持进行编译,并且不会正确设置字符集。如果没有,您可能需要更新它或自己编译它。

  • ,请确保您所在的计算机可以显示表情符号,并在运行任何查询之前运行 SET NAMES utf8mb4

一旦应用程序的每个级别都可以支持新字符,您应该能够使用它们而不会出现任何损坏。

4 byte Unicode characters aren't yet widely used, so not every application out there fully supports them. MySQL 5.5 works fine with 4 byte characters when properly configured – check if your other components can work with them as well.

Here's a few other things to check out:

  • Make sure all your tables' default character sets and text fields are converted to utf8mb4, in addition to setting the client & server character sets, e.g.
    ALTER TABLE mytable charset=utf8mb4, MODIFY COLUMN textfield1 VARCHAR(255) CHARACTER SET utf8mb4,MODIFY COLUMN textfield2 VARCHAR(255) CHARACTER SET utf8mb4; and so on.

    If your data is already in the utf8 character set, it should convert to utf8mb4 in place without any problems. As always, back up your data before trying!

  • Also make sure your app layer sets its database connections' character set to utf8mb4. Double-check this is actually happening – if you're running an older version of your chosen framework's mysql client library, it may not have been compiled with utf8mb4 support and it won't set the charset properly. If not, you may have to update it or compile it yourself.

  • When viewing your data through the mysql client, make sure you're on a machine that can display emoji, and run a SET NAMES utf8mb4 before running any queries.

Once every level of your application can support the new characters, you should be able to use them without any corruption.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文