MySQL invalid utf8 character string

https://stackoverflow.com/questions/35125933/mysql-utf8mb4-errors-when-saving-emojis
character_set_client, _connection, and _results must all be utf8mb4 for that shortcake to be eatable.
If SET NAMES utf8mb4 is executed, all three set correctly.

向MySQL中某个text类型的字段中写入emoji字符的时候出现的警告。除了设置table,column的编码为utf8mb4之外,还要记得设置数据库连接的编码。

程序连接的时候指定编码就正常了。我的mysql workbench客户端找不到设置编码的地方(Manage Server Connection - Advanced - Others 加入了charset的选项貌似不起作用),在mysql workbench中insert带有emoji的字符串就会报警告,并且写入的emoji变成了问号,这种情况下执行先执行语句SET NAMES utf8mb4再写入或者查询就正常了。

猜你喜欢

转载自www.cnblogs.com/gdme1320/p/8968792.html