//炬火不止,前进不息

解决 Typecho 使用 emoji 后报错: Database Query Error

分类在 全部计算机Typecho 6 评论

事出缘由是对原来的主题太不满意,换主题时修改友链页面遇到的,添加 emoji 表情 🔒 就报错 Database Query Error ,进调试模式也没给详细信息,初步怀疑是数据库字符集问题
到PMA下检查,把数据库编码格式修改为 utf8mb4 ,mysql 配置文件中修改默认编码还是不行,摸索了半天官方文档中发现还要修改数据库配置

详细解决方法:

执行SQL语句:
修改数据库和数据表的编码格式

ALTER DATABASE typecho CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
ALTER TABLE typecho_comments CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
ALTER TABLE typecho_contents CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
ALTER TABLE typecho_fields CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
ALTER TABLE typecho_metas CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
ALTER TABLE typecho_options CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
ALTER TABLE typecho_relationships CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
ALTER TABLE typecho_users CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

修改 MySQL 配置,将 utf8 编码转换成 utf8mb4 以确保支持

[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'

到网站根目录下,修改config.inc.php,找到
'charset' => 'utf8'
改为
'charset' => 'utf8mb4'

报错的原因是,UTF-8编码中,一个utf8数字占1个字节,一个utf8英文字母占1个字节,但对于庞大的中日韩超大字符集来说,可以是2个或是3个或是4个字节。Emoji表情是4个字节,而Mysql的utf8编码最多3个字节,所以数据插不进去,就会报错。

留言
  1. Bessie Amundson

    Hello from SendBulkMails.com,

    We have a special limited offer for you to send unlimited emails.

    We allow non-permission based emails and you won't ever get blocked.

    We also buy your domain for you and give you a clean IP and setup your DNS records.

    Check us out on SendBulkMails.com

    回复
  2. Julio Rankine

    Hello from BestLocalData.com

    Due to the pandemic BestLocalData.com is shutting down on the 14th of May.

    We have more than a 100 million records of Key Executives all over the world.

    We hope that this Data will serve other companies to succeed in their marketing efforts.

    We have reduced all the prices to next to nothing on our website BestLocalData.com

    We wish you the best in your future endeavours.

    回复
  3. Rolando Nail

    Hello from SendBulkMails.com,

    We have a special limited offer for you to send unlimited emails.

    We allow non-permission based emails and you won't ever get blocked.

    We also buy your domain for you and give you a clean IP and setup your DNS records.

    Check us out on SendBulkMails.com

    回复
  4. Charleswes

    MEET HOT LOCAL GIRLS TONIGHT WE GUARANTEE FREE SEX DATING IN YOUR CITY CLICK THE LINK:
    FREE SEX

    回复
  5. BLACK GUYS FUCK WHITE WOMAN --> 4erteg.ru
    Detail: http://4erteg.ru/ http://4erteg.ru/ http://4erteg.ru/

    回复
  6. Charleswes

    MEET HOT LOCAL GIRLS TONIGHT WE GUARANTEE FREE SEX DATING IN YOUR CITY CLICK THE LINK:
    FREE SEX

    回复