Report this

What is the reason for this report?

MySQL server has gone away

Posted on June 11, 2017

Hello! While running a PHP script I’ve encountered an error that says the MySQL server has gone away and it’s really getting annoying.

I’ve tried the following things with no success. Add these to /etc/mysql/my.cnf

wait_timeout = 28800
interactive_timeout = 28800
max_allowed_packet	= 256M

I’ve tried adding this to php.ini as well.

mysql.connect_timeout = 240

Nothing seems to work.

Thank you!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

where put this mysql.connect_timeout = 300 default_socket_timeout = 300 lines ?

Hi, what about if the error is in this line?

$link->ssl_set(‘client-key.pem’, ‘client-cert.pem’, ‘ca.pem’, NULL, NULL);

Hi @matthew6d

You shouldn’t need to change anything in MySQL - it’s by default set to some ridiculous high timeout. But PHP has normally a timeout on 30 or 60 seconds for most things. Can you set the following two PHP configurations (300 seconds = 5 minutes):

mysql.connect_timeout = 300
default_socket_timeout = 300

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.