简体   繁体   English

导入大型SQL文件

[英]Importing a large SQL file

I've seen a lot of questions regarding this topic, but going through these didn't help so I'm asking.. 我已经看到很多关于这个话题的问题,但是经历这些并没有帮助,所以我问...

I have a large sql file (around 50mb) which I cannot import using phpmyadmin as it's limited to 2.5mb. 我有一个大的sql文件(大约50mb)我无法使用phpmyadmin导入,因为它限制为2.5mb。

I've tried to use bigdump and I'm getting an error that says that says that I'm using "extended inserts or very long procedure definitions". 我试图使用bigdump并且我收到一条错误消息,表示我正在使用“扩展插入或非常长的过程定义”。

I've also tried using the source command from the console, which also gives me an error message saying that the defined max_allowed_packet is too low, after changing it to 128M (was 16M before) I'm getting another issue where during the source command I'm losing the connection to the DB server (hosted locally): 我也尝试过使用来自控制台的source命令,这也给我一个错误信息,说明定义的max_allowed_packet太低,将其更改为128M(之前是16M)我在source命令期间遇到另一个问题我正在丢失与数据库服务器的连接(在本地托管):

ERROR 2013 (HY000): Lost connection to MySQL server during query
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
ERROR:
Can't connect to the server

The solution I found to be working is to further increase the max_allowed_packet to 512M. 我发现工作的解决方案是进一步将max_allowed_packet增加到512M。

Then the following will work: 然后以下将工作:

mysql -u username -ppassword databasename < file.sql

In my case the problem ("Lost connection to MySQL Server during query") was in a corrupted dump file or in the misbehaving HDDs: 在我的情况下,问题(“查询期间与MySQL服务器的连接丢失”)是在损坏的转储文件或行为不当的硬盘驱动器中:

First, I made a dump on the main server and then copied that dump to the replication server. 首先,我在主服务器上进行了转储,然后将该转储复制到复制服务器。 But it seems the replication server had some problems with its HDDs and the dump became corrupted, ie MD5 of the original dump file on the main server was different from MD5 of the dump copy on the replication server. 但似乎复制服务器的硬盘存在问题,转储损坏,即主服务器上原始转储文件的MD5与复制服务器上转储副本的MD5不同。

Does this work from the console? 这是否可以在控制台上运行?

mysql -u username -ppassword databasename < file.sql

(Yes, there is no space between the -p and password ) (是的, -ppassword之间没有空格)

Are you exporting or importing. 您是出口还是进口? If you are importing try CSV format. 如果您要导入尝试CSV格式。

You can export into CSV and then import. 您可以导出为CSV然后导入。 If it still does not import because it is large CSV, then you can break the CSV yourself to make it smaller CSV files. 如果由于它是大型CSV仍然无法导入,则您可以自行中断CSV以使其成为较小的CSV文件。

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

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