MySQL 5.7.12 导入无法从具有 CHARACTER SET 'binary' 的字符串创建 JSON 值

MySQL 5.7.12 import cannot create a JSON value from a string with CHARACTER SET #39;binary#39;(MySQL 5.7.12 导入无法从具有 CHARACTER SET binary 的字符串创建 JSON 值)

本文介绍了MySQL 5.7.12 导入无法从具有 CHARACTER SET 'binary' 的字符串创建 JSON 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我导出了包含 JSON 列的数据库.迁移到新服务器后,我的导入每次都崩溃并出现如下错误:

I exported my database with JSON columns in it. After I migrated to a new server, my import crashed every time with an error like:

无法从带有 CHARACTER SET 'binary' 的字符串创建 JSON 值

cannot create a JSON value from a string with CHARACTER SET 'binary'

在 stackoverflow 上,我找到了这篇文章,但对我不起作用:mysqlimport 问题set @@character_set_database=binary";这会阻止加载 json 值

On stackoverflow, I found this post but didn't work for me: mysqlimport issues "set @@character_set_database=binary" which prevents loading json values

文件大小为 2GB,无法打开.

The file is 2GB and isn't possible to open the file.

有人想导入我的数据库文件吗?

Anyone has an idea to import my database file?

推荐答案

您可以将正则表达式应用于您导出的 SQL 文本,这会将您的二进制字符串转换为可插入的格式.当我遇到这个问题时,这是我快速而肮脏的修复

You can apply a regex to the SQL text which you exported which will convert your binary strings into an insertable format. This was my quick and dirty fix when I faced this issue

(X'[^,)]*')
CONVERT($1 using utf8mb4)

应用这个正则表达式意味着

Applying this regex means

INSERT INTO json_table (json_column) VALUES (X'7B22666F6F223A2022626172227D');

现在变成

INSERT INTO json_table (json_column) VALUES (CONVERT(X'7B22666F6F223A2022626172227D' using utf8mb4));

这篇关于MySQL 5.7.12 导入无法从具有 CHARACTER SET 'binary' 的字符串创建 JSON 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:MySQL 5.7.12 导入无法从具有 CHARACTER SET 'binary' 的字符串创建 JSON 值

基础教程推荐