如何在mysql中插入utf-8 mb4字符(表情符号在ios5中)? [英] How to insert utf-8 mb4 character(emoji in ios5) in mysql?

查看:139
本文介绍了如何在mysql中插入utf-8 mb4字符(表情符号在ios5中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是mysql 5.5.10,其character_sets是

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         |

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

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

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

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

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

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

我可以很好地存储iOS4的emojis,但不能存储iOS5。

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

我如何存储iOS5的表情符号?

How could I store iOS5's emojis?

请帮帮我。

推荐答案

4字节Unicode字符不是'但是广泛使用,所以不是每个应用程序都完全支持它们。正确配置后,MySQL 5.5可以正常使用4字节字符 - 检查你的其他组件是否也可以使用它们。

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:


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

如果您的数据已经在utf8字符集中,它应该在没有任何问题的情况下转换为utf8mb4。与往常一样,在尝试之前备份数据!

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!

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

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.

通过mysql客户端查看数据时,请确保您使用的是可以显示表情符号,并在运行任何查询之前运行 SET NAMES utf8mb4

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.

这篇关于如何在mysql中插入utf-8 mb4字符(表情符号在ios5中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆