MySQL server has gone away (error #2006)


I had to migrate a web site from one server to another, having phpMyAdmin as the db administration tool and the db dump from the old server. Problems I faced were trivial, yet I wasted plenty of time on fixing them.

  • File is bigger than the limit for uploaded files. – Thats easy, if you got access to the configuration file for your PHP installation: php.ini. Just edit the value of the variable upload_max_filesize = 10M. Value should be a bit above your file’s size.

So far, so good, I did that and after restarting the web server (apache or IIS) you get in your phpMyAdmin the new limit next to the upload button. Well, that’s fine, but after I tried to upload my (obviously) small 2Mb archive of the dump, I got to the following error message:

#2006 – MySQL server has gone away

Damn! Quite a lot of people did not have a clue what to do with that. Someone said something about max_allowed_packet variable… so I checked it out (SQL query):

select @@max_allowed_packet

Size of that was 1048576, which was a bit smaller than my dump, bot compressed or in plain sql. What I did was changing it to something bigger. Like adding a 0 at the end:

set global max_allowed_packet=10485760

And that fixed my problem. After the import I returned the old value to 1048576.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *