MySQL 5.7.20:无法使用CHARACTER SET'binary'从字符串创建JSON值 [英] Mysql 5.7.20: Cannot create a JSON value from a string with CHARACTER SET 'binary'
问题描述
当导入带有JSON列的表的SQL文件时,我遇到了这个问题.
I am facing this issue when importing an SQL file with a table with JSON column.
数据库具有
编码:utf8mb4
整理:utf8mb4_unicode_ci
这是带有json列的表:
Here's the table with the json column:
CREATE TABLE `tracking_data` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`route` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`data` json NOT NULL,
`user_id` int(10) unsigned NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
I have read answers from this question on stack overflow which suggest the table must be on utf8mb4
. Mine's already, but I am facing this issue still.
这仍然是错误:
第XXX行:无法使用CHARACTER SET从字符串创建JSON值 二进制".
Line XXX: Cannot create a JSON value from a string with CHARACTER SET 'binary'.
当我运行show session variables like 'char%';
时:
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 latin1
character_set_system utf8
character_sets_dir /usr/share/mysql/charsets/
我该如何解决? 谢谢!
How can I fix this? Thanks!
推荐答案
如果我的会话字符集是binary
,我可以重现您的错误:
I can reproduce your error if my session character set is binary
:
mysql [localhost] {msandbox} (test) > set names binary;
Query OK, 0 rows affected (0.00 sec)
mysql [localhost] {msandbox} (test) > insert into tracking_data (route, data, user_id) values ('route', '{"route": "value"}', 1);
ERROR 3144 (22032): Cannot create a JSON value from a string with CHARACTER SET 'binary'.
然后我可以通过将会话字符集设置为与表匹配的方式来修复它:
Then I can fix it by setting the session character set to match the table:
mysql [localhost] {msandbox} (test) > set names utf8mb4;
Query OK, 0 rows affected (0.00 sec)
mysql [localhost] {msandbox} (test) > insert into tracking_data (route, data, user_id) values ('route', '{"route": "value"}', 1);
Query OK, 1 row affected (0.01 sec)
所以我得出结论,您已将会话字符集设置为binary
.
So I conclude that you have set the session character set to binary
.
运行show session variables like 'char%';
并查看其内容.
这篇关于MySQL 5.7.20:无法使用CHARACTER SET'binary'从字符串创建JSON值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!