让mysql 支持 emoji 表情

时间:2022-06-20 17:11:41

1、数据库配置

[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'

2、数据库、数据表字符串设置

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 VARCHAR(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;    

3、数据库操作类的字符集设置

SET NAMES utf8mb4

PS:此处是要修改自己框架里的连接配置,例如: database.php -> charset,记得修改为 uft8mb4