首先驗證jdbc連接是否正確mysql
jdbc:mysql://ip:port/dbname?" + "user=user&password=password&useUnicode=true&autoReconnect=true&characterEncoding=utf8
而後驗證mysql配置sql
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';數據庫
重點觀察mysql配置是不是utf8mb4,如若不是檢查/etc/my.cnf是否有如下配置code
[client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4 [mysqld] character-set-client-handshake = FALSE character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci init_connect='SET NAMES utf8mb4'
最後檢查數據庫、表字段定義server
ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci; ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE table_name CHANGE column_name VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;