Incorrect string value错误解决

创建数据库时配置
character set为:utf8mb4
collation为:utf8mb4_unicode_ci

表的配置
character set为:utf8mb4
collation为:utf8mb4_general_ci

插入表情(例如?)时候报错
java.sql.SQLException: Incorrect string value: '\xF0\x9F\x94\xA50+...' 

执行show variables like 'character%' ;

character_set_client        utf8mb4
character_set_connection    utf8mb4
character_set_database        utf8mb4
character_set_filesystem    binary
character_set_server        utf8
character_set_system         utf8

原因是mysql客户端配置的字符集是utf8,修改mysql的配置文件
character_set_server=utf8mb4

重启mysql
执行show variables like 'character%' ;

character_set_client        utf8mb4
character_set_connection    utf8mb4
character_set_database        utf8mb4
character_set_filesystem    binary
character_set_server        utf8mb4
character_set_system         utf8

 

你可能感兴趣的:(sql,java)