1、确认编码字符集
SHOW VARIABLES WHERE Variable_name LIKE ‘character\_set\_%’ OR Variable_name LIKE ‘collation%’;
+————————–+——————–+
| 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 |
+————————–+——————–+
2、如果不是上面的,替换my.ini 文件(如果没有这个文件,修改my-default.ini,并重新确认字符集
[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′
3、老的数据库的字符集,字段字符集更改;表很多时这可能要用到脚本或程序来做了,可能用得到的sql 有
show tables; 查所有表
show full columns from XX 查表的列
ALTER TABLE t_chat_history DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci 修改表默认字符集
ALTER TABLE t_chat_history CHANGE f_text f_text VARCHAR(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 修改字段字符集
4、更新驱动mysql-connector-java-5.1.36.jar
5、注意编码变化可能引起的长度等其它问题.