如果數據庫觸發器記錄了在表上執行的所有查詢,並且該查詢包含4字節的UTF- 8個字符。當插入觸發器處於活動狀態時,將4字節UTF-8字符/表情符號插入MySQL數據庫時遇到問題
MySQL的版本是19年7月5日在Ubuntu 16.04
示例腳本:
show variables where Variable_name like 'character\_set\_%' or Variable_name like 'collation%';
drop database if exists my_test_db;
create database my_test_db;
use my_test_db;
create table my_test_table(id int not null primary key auto_increment, jdoc json not null);
create table my_test_table_log(id int not null primary key auto_increment, query varchar(1024) NOT NULL);
SELECT "insert works when trigger is not active" as "";
insert into my_test_table(jdoc) VALUES(JSON_OBJECT("Dubai was", ""));
DELIMITER |
CREATE TRIGGER log_my_test_table_queries_insert
BEFORE INSERT ON `my_test_table`
FOR EACH ROW
BEGIN
DECLARE original_query VARCHAR(1024);
SET original_query = (SELECT info
FROM INFORMATION_SCHEMA.PROCESSLIST
WHERE id = CONNECTION_ID());
INSERT INTO `my_test_table_log` (`query`) VALUES (original_query);
END;
|
DELIMITER ;
SELECT "insert doesn't work when trigger is active" as "";
insert into my_test_table(jdoc) VALUES(JSON_OBJECT("Dubai was", ""));
我的輸出:
+--------------------------+--------------------+
| Variable_name | Value |
+--------------------------+--------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| collation_connection | utf8mb4_unicode_ci |
| collation_database | utf8mb4_unicode_ci |
| collation_server | utf8mb4_unicode_ci |
+--------------------------+--------------------+
10 rows in set (0.00 sec)
Query OK, 2 rows affected (0.03 sec)
Query OK, 1 row affected (0.00 sec)
Database changed
Query OK, 0 rows affected (0.03 sec)
Query OK, 0 rows affected (0.02 sec)
+-----------------------------------------+
| |
+-----------------------------------------+
| insert works when trigger is not active |
+-----------------------------------------+
1 row in set (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
+--------------------------------------------+
| |
+--------------------------------------------+
| insert doesn't work when trigger is active |
+--------------------------------------------+
1 row in set (0.01 sec)
ERROR 1366 (HY000): Incorrect string value: '\xF0\x9F\x94\xA5")...' for column 'INFO' at row 1
數據庫似乎與創造正確的字符集
個SHOW CREATE TRIGGER log_my_test_table_queries_insert;
SHOW CREATE TABLE my_test_table;
SHOW CREATE TABLE my_test_table_log;
detailsdetailsdetails
有什麼消息嗎? – Philippe