jdbc端的characterEncoding=utf8 无法改为utf8mb4
测试:
create table utf8mb4_test (name1 varCHAR(20) CHARACTER SET utf8mb4, name2 varCHAR(20) CHARACTER SET utf8);
通过语句 stmt.execute("set names utf8mb4");
后再执行 stmt.execute("INSERT INTO risk_cds_education_audit_log(os_name,os_company_name)VALUES('1234test','王家园45\uD83D\uDC4C**')");
即可。此种情况,除了将目标表中的字段改为外,无需改动数据库任何地方。
SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';
grant All on poc.* to dbtest@'%' identified by 'Btmysql_1234';
如果mysqld group 设置了character_set_server=utf8mb4,则client端无需做任何改动即可使用。
For Connector/J 5.1.46 and earlier: In order to use the utf8mb4 character set for the connection, the server MUST be configured with character_set_server=utf8mb4; if that is not the case, when UTF-8 is used for characterEncoding in the connection string, it will map to the MySQL character set name utf8, which is an alias for utf8mb3.
For Connector/J 5.1.47 and later: When UTF-8 is used for characterEncoding in the connection string, it maps to the MySQL character set name utf8mb4.
驱动更换为5.1.47即可