14

I am trying to import a large sql dump (2GB) to my local mysql on my mac. I have been able to do this in the past (I was using MAMP), but now I get a ERROR 2006 (HY000) at line 7758: MySQL server has gone away everytime I try to import the dump. The database contains innodb tables.

I tried copying the my-innodb-heavy-4G.cnf file to my my.cnf to see if those settings would help, but no luck.

Any ideas on what to tweak?

I am using the "Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive" from here: http://dev.mysql.com/downloads/mysql/

5 Answers 5

16

One of the silent killers of MySQL Connections is the MySQL Packet. Even the I/O Thread of MySQL Replication can be victimized by this.

According to the MySQL Documentation

  • You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld receives a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection. If you need big queries (for example, if you are working with big BLOB columns), you can increase the query limit by setting the server's max_allowed_packet variable, which has a default value of 1MB. You may also need to increase the maximum packet size on the client end. More information on setting the packet size is given in Section C.5.2.10, “Packet too large”.

  • An INSERT or REPLACE statement that inserts a great many rows can also cause these sorts of errors. Either one of these statements sends a single request to the server irrespective of the number of rows to be inserted; thus, you can often avoid the error by reducing the number of rows sent per INSERT or REPLACE.

At the very least, you must make sure the packet sizes for both the machine you mysqldump'd from and the machine you are loading are identical.

There may be two(2) approaches you can take:

APPROACH #1 : Perform the mysqldump using --skip-extended-insert

This will make sure the MySQL Packet is not inundated with multiple BLOBs, TEXT fields. That way SQL INSERTs are performed one at a time. The major drawbacks are

  1. the mysqldump is much larger
  2. reloading such a dump takes much longer.

APPROACH #2 : Increase max_allowed_packet

This may be the preferred approach because implementing this is just a mysql restart away. Understanding what the MySQL Packet is may clarify this.

According to the page 99 of "Understanding MySQL Internals" (ISBN 0-596-00957-7), here are paragraphs 1-3 explaining it:

MySQL network communication code was written under the assumption that queries are always reasonably short, and therefore can be sent to and processed by the server in one chunk, which is called a packet in MySQL terminology. The server allocates the memory for a temporary buffer to store the packet, and it requests enough to fit it entirely. This architecture requires a precaution to avoid having the server run out of memory---a cap on the size of the packet, which this option accomplishes.

The code of interest in relation to this option is found in sql/net_serv.cc. Take a look at my_net_read(), then follow the call to my_real_read() and pay particular attention to net_realloc().

This variable also limits the length of a result of many string functons. See sql/field.cc and sql/intem_strfunc.cc for details.

Given this explanation, making bulk INSERTs will load/unload a MySQL Packet rather quickly. This is especially true when max_allowed_packet is too small for the given load of data coming at it.

CONCLUSION

In most installs of MySQL, I usually set this to 256M or 512M. You should experiement with larger values when data loads produces "MySQL has gone away" errors.

6
  • I tried settting max_allowed_packet to 900M and I was using --skip-extended-insert (and you are right - that makes for huuuge db-dumps), but it still fails. I am suspecting a particular line in the dump now that I can probably work around. But it is still weird - the dump can be imported fine on my CentOS server.
    – naxoc
    Sep 2, 2011 at 9:26
  • I ended up removing an insert from the sql dump that was a very, very long line. That fixed it (and the line was not needed).
    – naxoc
    Sep 3, 2011 at 8:44
  • BTW please make sure the default character for the data dump can be supported in MacOSX Operating System and in MySQL. Sep 3, 2011 at 19:49
  • @naxov - I am just curious about the one line you suspect in the dump. Are there any TEXT or BLOB fields involved ??? Sep 3, 2011 at 20:00
  • Yes a very long textfield.
    – naxoc
    Dec 8, 2011 at 15:57
2

How long does this run before timing out? First step would bet to check the wait_timeout and interactive_timeout settings to make sure they're large enough for your import:

SHOW VARIABLES LIKE '%_timeout';
SET SESSION wait_timeout=28800;

The default is 8 hours (28800), so that's potentially not the issue. Other indications of this issue can be found here. One that stands out is this:

A client application running on a different host does not have the necessary privileges to connect to the MySQL server from that host.

Verify permissions first, but then go through that list of potential problems.

1
  • It is all on localhost, so either I don't understand what you mean or it is not the problem. Did you mean permissions as in privileges in mysql?
    – naxoc
    Sep 2, 2011 at 9:27
2

Yeah usually playing with wait_timeout and max_allowed_packets allows me to get around the error message as well.

2
  • That didn't work for me. I had to edit the sql in the dump file and remove a very long line that was causing the problem.
    – naxoc
    Sep 3, 2011 at 8:44
  • one should not play with some parameters he doesn't understand
    – Jeredepp
    May 27, 2014 at 8:58
2

It may not be the "correct" thing to do, but it might work (get 'er done, right?):

Try breaking your large dump into multiple files and running them one at a time in sequence. My approach would be to break it in half and test. Then break each half in half, re-test, and so on.

I'm somewhat curious if the amount of RAM you've got on your box could have something to do with this. Does MySQL load the whole dump into memory when it goes to run it? I don't know...but if you only have 2GB of RAM and some of it is in use running your OS and other apps, then this might be the problem.

2

Those who have not had success with the other suggestions might consider taking a look at the BigDump PHP staggered MySQL dump importer script.

It's a workaround for importing large database dumps into MySQL. I have used it successfully to import a large MySQL dump into my local development environment (I am using MAMP in this case).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.