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‘,
时间: 2024-10-24 18:40:59