mysql 插入emoji字符的相关问题咨询

zgw06629 发布于 2015/05/02 11:26
阅读 1K+
收藏 0

如下所示:

mysql> show variables like 'character%';
+--------------------------+---------------------------------------+
| Variable_name            | Value                                 |
+--------------------------+---------------------------------------+
| character_set_client     | utf8                                  |
| character_set_connection | utf8                                  |
| character_set_database   | latin1                                |
| character_set_filesystem | binary                                |
| character_set_results    | utf8                                  |
| character_set_server     | latin1                                |
| character_set_system     | utf8                                  |
| character_sets_dir       | /opt/mysql/server-5.6/share/charsets/ |
+--------------------------+---------------------------------------+
CREATE TABLE `t` (
  `data` varchar(10) CHARACTER SET utf8mb4 DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1

mysql> insert into t select '\U+1F600';
ERROR 1366 (HY000): Incorrect string value: '\xF0\x9F\x98\x80' for column 'data' at row 1

mysql> set names utf8mb4;
mysql> insert into t select '\U+1F600';
Query OK, 1 row affected (0.01 sec)

我的问题是,不是已经正确解析出是4个字节的utf8mb4字符(f0 9f 98 80)了吗?

为什么还需要显式执行set names utf8mb4, 才能成功插入呢?

另外在下面字符集环境会话中的操作,让我彻底的乱了.

mysql> show variables like 'character%';
+--------------------------+---------------------------------------+
| Variable_name            | Value                                 |
+--------------------------+---------------------------------------+
| character_set_client     | latin1                                |
| character_set_connection | latin1                                |
| character_set_database   | latin1                                |
| character_set_filesystem | binary                                |
| character_set_results    | latin1                                |
| character_set_server     | latin1                                |
| character_set_system     | utf8                                  |
| character_sets_dir       | /opt/mysql/server-5.6/share/charsets/ |
+--------------------------+---------------------------------------+

mysql> insert into t select '\U+1F600';
Query OK, 1 row affected (0.00 sec

emoji字符不是只有utf8mb4才支持吗? 怎么连latin1也支持呢? 我以为这种情况下应该是乱码啊?如??.且hex(data)应该也只有两个字节啊,如3f 3f.

求释惑!

加载中
0
kerriganA
kerriganA
la也是支持的。。
zgw06629
zgw06629
可有相关文档 我想看一下 谢谢!
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部
返回顶部
顶部