1.如果是阿里云数据库
a.控制台-》修改参数character_set_server参数为UTF8mb4
b.设置库的字符集为UTF8mb4
2.如果是自己mysql服务器
[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'
3.修改数据表还有字段
ALTER TABLE `user` MODIFY COLUMN nickname VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; ALTER TABLE `user` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
4.修改库连接
'charset' => 'utf8mb4',
5.网页显示emoji
确保MySQL 能存储 emoji 字符后, 存储前 字符串 可以 序列化一下(serialize),效果如下: 这里用了jquery 插件添加表情符