起因
博客添加了分类,想在前边放个图标,发现报错:Database Query Error。我就各种百度发现是数据库编码的问题,因为我放的图标属于表情(emoji)所以需要修改书库编码。正常编码是utf8编码,想要支持表情就要改成utf8mb4编码。
开始
修改数据库的配置文件
网站根目录数据库配置文件config.inc.php,大约在60行/** 定义数据库参数 */
$db = new Typecho_Db('Pdo_Mysql', 'typecho_');
$db->addServer(array (
...
'charset' => 'utf8mb4', // 将原来的utf8修改为 utf8mb4
...
), Typecho_Db::READ | Typecho_Db::WRITE);
Typecho_Db::set($db);
修改数据库编码
进入数据库,直接运行下列语句:alter table typecho_comments convert to character set utf8mb4 collate utf8mb4_general_ci;
alter table typecho_contents convert to character set utf8mb4 collate utf8mb4_general_ci;
alter table typecho_fields convert to character set utf8mb4 collate utf8mb4_general_ci;
alter table typecho_metas convert to character set utf8mb4 collate utf8mb4_general_ci;
alter table typecho_options convert to character set utf8mb4 collate utf8mb4_general_ci;
alter table typecho_relationships convert to character set utf8mb4 collate utf8mb4_general_ci;
alter table typecho_users convert to character set utf8mb4 collate utf8mb4_general_ci;