将大型 .sql 文件导入 MySQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14161173/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:02:28  来源:igfitidea点击:

Import large .sql file into MySQL

mysqlmysql-workbenchdatabase-restore

提问by w00

I have been given a VERYlarge mysql backup file. It is ~630 MB... I guess someone thought it was a good idea to store images in a database... Anyway, I need to restore the data somehow in MySQL. But i can't get it done because of the filesize.

我得到了一个非常大的 mysql 备份文件。它是~630 MB...我猜有人认为将图像存储在数据库中是个好主意...无论如何,我需要以某种方式在MySQL中恢复数据。但由于文件大小,我无法完成。

At first i tried to do it with MySQL Workbench. But when i try to import the file it gives me the following error:

起初我尝试用 MySQL Workbench 来做。但是当我尝试导入文件时,它给了我以下错误:

Could not allocate xxxxx bytes to read file C:\backup.sql

无法分配 xxxxx 字节来读取文件 C:\backup.sql

Then i tried to do it through command prompt. I entered the following in cmd:

然后我尝试通过命令提示符来完成。我输入了以下内容cmd

C:\> mysql -u user -pPassword database < C:\backups.sql

That eventually gives me the following warning:

这最终给了我以下警告:

ERROR 2006 (HY000) at line 68230: MySQL server has gone away

第 68230 行的 ERROR 2006 (HY000):MySQL 服务器已消失

Guess that is also because of the big filesize?

猜猜这也是因为文件大吗?

I have no other ideas on how to restore the data. Is that still possible somehow?

我对如何恢复数据没有其他想法。这还有可能吗?

采纳答案by Salman A

Increasing the wait_timeoutand/or interactive_timeoutshould help. First check the current value:

增加wait_timeout和/或interactive_timeout应该有帮助。首先检查当前值:

C:\> mysql -hlocalhost -uroot -proot

mysql> SHOW VARIABLES LIKE 'wait_timeout';

If this is very low (e.g. 30 seconds) then increase it (e.g. 5 minutes):

如果这非常低(例如 30 秒),则增加它(例如 5 分钟):

mysql> SET SESSION wait_timeout = 300;
mysql> SET SESSION interactive_timeout = 300;

Then execute your SQL file:

然后执行你的 SQL 文件:

mysql> \. database.sql

回答by Salman A

I had a 3.5G dump file, I tried to import it with PhpMyAdmin and MySql workbench but without success. So I just used the console to run it

我有一个 3.5G 的转储文件,我尝试使用 PhpMyAdmin 和 MySql 工作台导入它,但没有成功。所以我只是用控制台来运行它

# mysql -u user_name -pYour_passwd your_db < your_dump.sql

and it works great

而且效果很好