将Mysql的编码从utf8转换成utf8mb4。
需要 >= MySQL 5.5.3版本、(经检测5.5.29的也可以)低版本不支持这个字符集、复制报错
停止MySQL Server服务
修改 my.cnf或者mysql.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'
重启 MySQL Server:service mysql restart ,检查字符集
SHOW VARIABLES WHERE Variable_name LIKE 'character%' OR Variable_name LIKE 'collation%';
修改数据库字符集:
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 column_name VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
程序中使用mysql-connector-java-5.1.18.jar或更高版本
数据库连接使用 ?useUnicode=true
jdbc:mysql://127.0.0.1:3306/o2o_user_suda?useUnicode=true
########################################
ALTER DATABASE `o2o_user_onetime` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
ALTER TABLE order_info CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
SHOW VARIABLES WHERE Variable_name LIKE 'character%' OR Variable_name LIKE 'collation%';
SET character_set_client = utf8mb4 ;
SET character_set_connection = utf8mb4 ;
SET character_set_results = utf8mb4 ;
SET character_set_server = utf8mb4 ;