每次发布带有emoji表情的文章就显示数据库错误 查找了相关资料 原因是emoji表情是4个字节 而utf8只能3个字节 所以需要修改数据库的排序规则为utf8mb4_unicode_ci

修改数据库 charset 为 utf8mb4:

alter table typecho_comments convert to character set utf8mb4 collate utf8mb4_unicode_ci;
alter table typecho_contents convert to character set utf8mb4 collate utf8mb4_unicode_ci;
alter table typecho_fields convert to character set utf8mb4 collate utf8mb4_unicode_ci;
alter table typecho_metas convert to character set utf8mb4 collate utf8mb4_unicode_ci;
alter table typecho_options convert to character set utf8mb4 collate utf8mb4_unicode_ci;
alter table typecho_relationships convert to character set utf8mb4 collate utf8mb4_unicode_ci;
alter table typecho_users convert to character set utf8mb4 collate utf8mb4_unicode_ci;

修改 Typecho 配置文件中数据库定义参数中的 charset 为 utf8mb4:

$db->addServer(array (
'host'      =>  localhost,
'user'      =>  'me',
'password'  =>  'my_password',
'charset'   =>  'utf8mb4', //修改这一行
'port'      =>  3306,
'database'  =>  'xxx'
), Typecho_Db::READ | Typecho_Db::WRITE);

温馨提示

  • 操作前备份好数据 🙃 不然网站down了别怪我😂