walinejs / waline

💬 A Simple, Safe Comment System
https://waline.js.org/en/
GNU General Public License v2.0
2.19k stars 379 forks source link

[BUG] MySQL 存储 Emoji 展示有问题 #197

Closed lizheming closed 3 years ago

lizheming commented 3 years ago

问题描述 | Describe the bug

Emoji 无法正常展示

问题网站 | Website URL

部署方式 | Deploy Type

ichenkaihua commented 3 years ago

@lizheming 之前配置过,貌似不支持mysql8,最后使用了sqlite

lizheming commented 3 years ago

@lizheming 之前配置过,貌似不支持mysql8,最后使用了sqlite

MySQL 8 的支持需要修改默认的加密连接方式 https://zach.vip/server/mysql8-0默认加密连接方式修改/

然后将数据的表的字符集修改为 utf8mb4 并添加 MYSQL_ENCODING=utf8mb4 应该就行。

SakuragawaAsaba commented 3 years ago

然后将数据的表的字符集修改为 utf8mb4 并添加 MYSQL_ENCODING=utf8mb4 应该就行。

MYSQL_ENCODING 環境變數最後會給 mysql 傳遞 encoding: utf8mb4 參數,但在 mysql 的文檔中並無此參數,是否應使用 charset: UTF8_GENERAL_CI

charset: The charset for the connection. This is called "collation" in the SQL-level of MySQL (like utf8_general_ci). If a SQL-level charset is specified (like utf8mb4) then the default collation for that charset is used. (Default: 'UTF8_GENERAL_CI')

(Ref: https://github.com/mysqljs/mysql/tree/v2.16.0#connection-options)

lizheming commented 3 years ago

然后将数据的表的字符集修改为 utf8mb4 并添加 MYSQL_ENCODING=utf8mb4 应该就行。

MYSQL_ENCODING 環境變數最後會給 mysql 傳遞 encoding: utf8mb4 參數,但在 mysql 的文檔中並無此參數,是否應使用 charset: UTF8_GENERAL_CI

charset: The charset for the connection. This is called "collation" in the SQL-level

of MySQL (like utf8_general_ci). If a SQL-level charset is specified (like utf8mb4)

then the default collation for that charset is used. (Default: 'UTF8_GENERAL_CI')

(Ref: https://github.com/mysqljs/mysql/tree/v2.16.0#connection-options)

image

文档中有说明哦,而且代码里也有定义的,看 https://github.com/mysqljs/mysql/blob/v2.16.0/lib/protocol/constants/charsets.js 倒数第二行

SakuragawaAsaba commented 3 years ago

文档中有说明哦,而且代码里也有定义的,看 mysqljs/mysql@v2.16.0/lib/protocol/constants/charsets.js 倒数第二行

https://github.com/lizheming/waline/blob/b96c9f0dbcc2a158c39e9933624634febb4448a0/packages/server/src/config/adapter.js#L96

我猜測問題在於應傳遞 charset 參數,而非目前的 encoding 參數。目前讀取的 MYSQL_ENCODING 環境變數也應變爲讀取 MYSQL_CHARSET

lizheming commented 3 years ago

哦,这个好像是的,我明天确认下改一下。之前其他项目里好像有人反馈过。