MySQL在5.5.3版本之后增加了这个utf8mb4的编码,mb4就是most bytes 4的意思,专门用来兼容四字节的unicode。其实,utf8mb4是utf8的超集,理论上原来使用utf8,然后将字符集修改为utf8mb4,也不会对已有的utf8编码读取产生任何问题。
#修改数据库:
ALTER DATABASE mydatabse CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
#修改表编码为utf8mb4
ALTER TABLE mytable CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
#修改表字段编码为utf8mb4
ALTER TABLE mytable CHANGE nickname nickname VARCHAR(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
#编辑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'
#重启MYSQL
service mysqld restart
#查看编码字符集
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';