Mysql

MySQL (5.6) 觸發器是否支持 4 字節表情符號?

  • February 6, 2022

我正在使用具有以下設置的 MySQL 5.6.34:

"character_set_client","utf8mb4"
"character_set_connection","utf8mb4"
"character_set_database","utf8mb4"
"character_set_filesystem","utf8mb4"
"character_set_results","utf8mb4"
"character_set_server","utf8mb4"
"character_set_system","utf8"
"collation_connection","utf8mb4_general_ci"
"collation_database","utf8mb4_unicode_ci"
"collation_server","utf8mb4_unicode_ci"

3 字節表情符號似乎在觸發器中正常工作,但 4 字節不。他們只是變成了“?”。是否應該使用其他設置,或者觸發器中不支持此設置?

如在github問題中,建議更改以下設置:

connection_charset: utf8mb4
connection_collation: utf8mb4_unicode_ci
charset: utf8mb4
collation: utf8mb4_unicode_ci

我想你可以改變

"collation_connection","utf8mb4_general_ci"

"collation_connection","utf8mb4_unicode_ci"

當涉及到 3 字節編碼與 4 字節時,排序規則是無關緊要的。

檢查SHOW CREATE TABLE該列是否可以接受 utf8mb4。

檢查SHOW CREATE TRIGGER創建觸發器時的字元集是什麼。(這可能是您遇到麻煩的原因。)範例:

mysql> SHOW CREATE TRIGGER t3trig\G
*************************** 1. row ***************************
              Trigger: t3trig
             sql_mode: 
SQL Original Statement: CREATE DEFINER=`root`@`127.0.0.1` trigger t3trig before insert on t3 for each row ...
 character_set_client: utf8
 collation_connection: utf8_general_ci
   Database Collation: utf8mb4_unicode_520_ci
1 row in set (0.00 sec)

此觸發器可能會遇到與您相同的問題。

解決方案可能是設置所需的字元集並重新創建觸發器:

SET NAMES utf8mb4;
DROP TRIGGER ...;
CREATE TRIGGER ...;

而且,在您問之前,沒有“更改觸發器”:https ://dba.stackexchange.com/a/78442/1876

引用自:https://dba.stackexchange.com/questions/215238