修改my.cnf配置 增加内容
[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'
执行修改数据库的修改
数据库
ALTER DATABASE testInfo CHARACTER SET = utf8mb4 COLLATE = utf8m
b4_unicode_ci;
表
ALTER TABLE new_table CONVERT TO CHARACTER SET utf8mb4 COLLATE
utf8mb4_unicode_ci;
字段
ALTER TABLE new_table CONVERT TO CHARACTER SET utf8mb4 COLLATE
utf8mb4_unicode_ci;
重启数据库
/etc/init.d/mysql restart
最后效果
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 |
| character_sets_dir | /usr/share/mysql/charsets/ |
| collation_connection | utf8mb4_unicode_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+--------------------------+----------------------------+