更改MySQL数据库的编码为utf8mb4
utf8mb4编码是utf8编码的超集,兼容utf8,并且能存储4字节的表情字符。
采用utf8mb4编码的好处是:存储与获取数据的时候,不用再考虑微信昵称nickname、表情字符的编码与解码报错异常问题。
1\连接Mysql数据库的时候
String url = "jdbc:mysql://localhost:3306/credit?autoReconnect=true&useUnicode=true&characterEncoding=utf8"
2\/**修改mysql配置文件f
f一般在etc/mysql/f位置。找到后请在以下三部分里添加如下内容:
[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
alter database jenze_test character set utf8mb4;
ALTER TABLE weixin_user_info CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
ALTER TABLE `weixin_user_info`
CHANGE COLUMN `nickName` `nickName` VARCHAR(255) CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_general_ci' NULL DEFAULT NULL;
-- set character_set_system= utf8mb4;
set character_set_server=utf8mb4;
set collation_connection=utf8mb4_general_ci;
set collation_database=utf8mb4_general_ci;
set collation_server=utf8mb4_general_ci;
show full columns from weixin_user_info;
show variables WHERE Variable_name LIKE 'char%' OR Variable_name LIKE 'collation%';