//炬火不止,前进不息

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

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

事出缘由是对原来的主题太不满意,换主题时修改友链页面遇到的,添加 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. Guadalupe Albiston

    Hello from order-fulfillment.net,

    Doing your own product shipping or order fulfillment in house?

    Tired of it? Visit us on www.order-fulfillment.net

    We can store, inventory, and manage your drop shipping / order fulfillment for you.

    Based in the US for almost 2 decades - we ship around the world and will save you time and money.

    Who would be the best contact at your company to discuss?

    Here are some of the items we ship for clients:
    -Books, training manuals, guides
    -New member welcomes boxes and gifts
    -Product samples
    -Marketing materials
    -Medical program test kits
    -Follow up gifts to clients, leads, and prospects

    Thank you!
    Fulfillment Warehouse
    https://order-fulfillment.net

    回复
  2. Jenni Paredes

    We at BestLocalData.com has been hit badly by Covid-19 and as a result BestLocalData.com is shutting down.

    We provided the best data to companies to find their right customer base, we don't want other companies to go down the same path we went and go out of business.

    As a result we are providing our data till the end of the week at the lowest possible prices.

    BestLocalData.com

    回复
  3. Edgar Kopf

    Hello,

    It is with sad regret to inform you that BestLocalData.com is shutting down.

    We have made all our databases for sale for a once-off price.

    Visit our website to get the best bargain of your life. BestLocalData.com

    Regards,
    Edgar

    回复
  4. Tammie Sutton

    Hello,

    It is with sad regret to inform you that BestLocalData.com is shutting down.

    We have made all our databases for sale for a once-off price.

    Visit our website to get the best bargain of your life. BestLocalData.com

    Regards,
    Tammie

    回复