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即可