MYSQL的Workbench设置字符集失败,可以用以下命令行方式设置MYSQL字符集:
在my.cnf中设置:
[client]
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysql]default-character-set = utf8mb4
检查设置是否生效:
SHOW VARIABLES LIKE 'char%'; SHOW VARIABLES LIKE 'collation%';
结果如下为设置成功:
对于已经存在的表,使用如下命令修改字符集:
ALTER DATABASE databasename CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;