一、確認編碼字符集
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';java
+--------------------------+--------------------+
| Variable_name | Value |
+--------------------------+--------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| collation_connection | utf8mb4_unicode_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+--------------------------+--------------------+mysql
二、若是不是上面的,替換my.ini 文件(若是沒有這個文件,修改my-default.ini,並從新確認字符集sql
[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'code
三、老的數據庫的字符集,字段字符集更改;表不少時這可能要用到腳本或程序來作了,可能用獲得的sql 有server
show tables; 查全部表ci
show full columns from XX 查表的列unicode
ALTER TABLE t_chat_history DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci 修改表默認字符集it
ALTER TABLE t_chat_history CHANGE f_text f_text VARCHAR(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 修改字段字符集
四、更新驅動mysql-connector-java-5.1.36.jar
五、注意編碼變化可能引發的長度等其它問題.