0

I am moving a MySQL database from a now inaccessible server to a new one. The dump contains tables which in turn contain binary blobs, which seems to cause trouble with the MySQL command line client. When trying to restore the database, I get the following error:

ERROR at line 694: Unknown command '\''.

I inspected the line at which the error is occurring and found that it is a huge insert statement (approx. 900k characters in length) which seems to insert binary blobs into a table.

Now, I have found these two questions that seem to be connected to mine. However, both answers proved to not solve my issue. Adding --default-character-set=utf8 or even --default-caracter-set=latin1 didn't change anything and creating a dump with --hex-dump is not possible because the source database server is no longer accessible.

Is there any way how I can restore this backup via the MySQL command line client? If yes, what do I need to do?

Please let me know if you need any additional information.

Thanks in advance.

EDIT: I am using MySQL 5.6.35. Also, in addition to the attempts outlined above, I have already tried increasing the max_allowed_packet system variable to its maximum value - on both server and client - but to no avail.

4

2 回答 2

0

没有解决方案,只是确认我在包含长 JSON 字符串的“文本”字段类型中看到了相同的行为。MySQLdump 生成的 SQL(备份)文件有一个 INSERT 语句,它将特定文本字段的长度截断为“大约”64K(有许多转义引号/双引号和各种 UTF-8 字符) - 没有发出警告发生了这样的截断。

由于 JSON 格式的字符串过早终止,恢复到 JSON 列自然会失败。

在这种情况下奇怪的是,备份表中的列被定义为 TEXT,实际上应该限制为 64 KB。凭直觉,我将备份表的架构更改为 MEDIUMTEXT。在那之后,MySQLdump 不再在 INSERT 语句中截断超过 64K 的字符串。

似乎 MySQLdump 不只是输出整个列,而是截断到它认为最大字符串长度应该基于模式信息的任何内容,并且在截断时不会发出警告。

于 2017-04-27T17:01:42.823 回答
0

如果我没记错的话,您需要将 my.cnf 中的 max_allowed_pa​​cket 设置为足够大的值以容纳转储文件中的最大数据 blob,然后重新启动 MySQL 服务器。

然后,您可以使用这样的恢复命令:

mysql --max_allowed_packet=64M  < your_dumpfile.sql

更多信息在这里:[ https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_max_allowed_pa​​cket]

于 2017-02-21T23:53:18.317 回答