mysql 插入emoji字符的相关问题咨询
如下所示:
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: 'xF0x9Fx98x80' 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.
求释惑!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可有相关文档 我想看一下 谢谢!
la也是支持的。。