简体   繁体   English

使用二进制Blob恢复MySQL转储

[英]Restoring a MySQL dump with binary blobs

I am moving a MySQL database from a now inaccessible server to a new one. 我正在将MySQL数据库从现在无法访问的服务器移至新服务器。 The dump contains tables which in turn contain binary blobs, which seems to cause trouble with the MySQL command line client. 转储包含的表又包含二进制blob,这似乎在MySQL命令行客户端中引起麻烦。 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. 我检查了发生错误的行,发现这是一个巨大的insert语句(长度约为900k个字符),似乎将二进制blob插入到表中。

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. 添加--default-character-set=utf8甚至--default-caracter-set=latin1不会更改任何内容,并且无法使用--hex-dump创建转储,因为无法再访问源数据库服务器。

Is there any way how I can restore this backup via the MySQL command line client? 有什么方法可以通过MySQL命令行客户端还原此备份? 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. 编辑:我正在使用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. 此外,除了上面概述的尝试外,我已经尝试将max_allowed_packet系统变量增加到最大值(在服务器和客户端上),但无济于事。

If I remember correctly, you need to set the max_allowed_packet in your my.cnf to a large enough value to accommodate the largest data blob in your dump file, and restart the MySQL server. 如果我没记错的话,您需要将my.cnf中的max_allowed_pa​​cket设置为足够大的值,以容纳转储文件中最大的数据blob,然后重新启动MySQL服务器。

Then, you can use a restore command like this one : 然后,您可以使用像这样的还原命令:

mysql --max_allowed_packet=64M  < your_dumpfile.sql

More info here : [ https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_max_allowed_packet] 此处提供更多信息:[ https://dev.mysql.com/doc/refman/5.6/zh-CN/server-system-variables.html#sysvar_max_allowed_pa​​cket]

No solution, just confirming that I had seen the same behavior with a "text" field type that contains a long JSON string. 没有解决方案,只是确认我已经看到了包含长JSON字符串的“文本”字段类型的相同行为。 The SQL (backup) file that MySQLdump generates has an INSERT statement and it truncates the length of that particular text field to "about" 64K (there are many escaped quotes/double-quotes and various UTF-8 characters) - without issuing a warning that such truncation had occurred. MySQLdump生成的SQL(备份)文件具有INSERT语句,并且将特定文本字段的长度截断为“大约” 64K(有许多转义的引号/双引号和各种UTF-8字符)-不会发出警告这种截断已经发生。

Naturally the restore into a JSON column fails because of the premature termination of the JSON formatted string. 自然,由于JSON格式的字符串过早终止,还原到JSON列的操作失败。

What was odd in this case, that the column in the backed-up table was defined as TEXT, which indeed should have been limited to 64 KB. 在这种情况下,奇怪的是,已将备份表中的列定义为TEXT,而该列实际上应该限制为64 KB。 On a hunch, I changed the schema for the backed up table to MEDIUMTEXT. 出于预感,我将备份表的架构更改为MEDIUMTEXT。 After THAT MySQLdump no longer truncated that string in the INSERT statement somewhere beyond 64K. 之后,MySQLdump不再将INSERT语句中的字符串截断到64K以上。

It appears as if MySQLdump doesn't just output the entire column, but truncates to whatever it thinks the maximum string length should be based on schema information, and does NOT issue warnings when it does truncate. 看起来MySQLdump不仅会输出整个列,还会截断到它认为最大字符串长度应基于架构信息的任何内容,并且在截断时不会发出警告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM