修改数据库字符集为utf8mb4,便于支持表情符
1,修改database默认的字符集
mysql> ALTER DATABASE gugehome CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
Query OK, 1 row affected (0.00 sec)
2,修改了相关字段,但是原来帖子中的表情也显示不出来了
ALTER TABLE ty_main CHANGE main_title main_title VARCHAR(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE ty_main CHANGE main_info main_info VARCHAR(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE ty_post CHANGE post_title VARCHAR(300) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE ty_post CHANGE content_text content_text text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE ty_post CHANGE content_html content_html text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
3,修改配置文件
SET NAMES utf8 COLLATE utf8_unicode_ci becomes SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci
> vim /etc/my.cnf
# 对本地的mysql客户端的配置
[client]
default-character-set = utf8mb4
# 对其他远程连接的mysql客户端的配置
[mysql]
default-character-set = utf8mb4
# 本地mysql服务的配置
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect=|SET NAMES utf8mb4|
--保存退出,重启服务
> service mysqld restart
4,修复&优化所有数据表
> mysqlcheck -u root -p --auto-repair --optimize --all-databases
详细更多设置:https://tdlib.com/am.php?t=2257
详细更多设置:https://tdlib.com/am.php?t=2257
【版權聲明】