MySQL server has gone away error can occur when you have an established connection to the MySQL server and for one reason or another, the connection times out or otherwise goes down. In the context of a Linux system, the error can sometimes be seen from the MySQL client. In this tutorial, we will show several solutions for dealing with and troubleshooting the MySQL error.
In this tutorial you will learn:
- How to resolve the
Mysql server has gone awayerror on Linux
|Requirements, Conventions or Software Version Used
|Any Ubuntu Linux based system
|MySQL server and client
|Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Mysql server has gone away – List of possible fixes
MySQL server has gone away error is somewhat generic and could be caused from a variety of different issues. Therefore we will look at some of the most common culprits below, as well as the fixes which must be applied in order to keep the error from occuring again.
- The most common cause of this problem is that your connection has simply timed out. This will happen in your MySQL client if you have not sent any data to or from the server within a certain amount of time. The default time out is quite long – 8 hours. But the server you are dealing with could have a much shorter time out. To adjust the time out setting, edit the
/etc/mysql/my.cnffile with the following lines.
[mysqld] wait_timeout = 31536000 interactive_timeout = 31536000
Note that these numbers are in seconds. Adjust to your desired time out as necessary.
- Another cause of this error is that the server was terminated unexpectedly. This could be a sudden sysem shutdown or perhaps the MySQL server was exited ungracefully with the
kill -9command. In either case, you will receive the
MySQL server has gone awayerror in your client. You must then investigate why the server is shutting down unexpectedly.
- The error will also occur if you are trying to execute a command on a server that has already timed out. In that case, you must first reestablish your connection to the MySQL server before trying to execute another command to retrieve or send data.
- If your MySQL client does not have permission to connect to the MySQL server, you may see this error pop up. Ensure that your username has permissions to connect from your host’s IP address, or from all IP addresses (wildcard).
- In some cases the error will be present when trying to send data that is too large. To prevent this, you must adjust the max packet size in the
/etc/mysql/my.cnffile. By default, the max packet size is 64 MB. Adjust the following setting according to your needs.
[mysqld] max_allowed_packet = 100M
Note that in this example we have set our max packet size to 100 MB.
In this tutorial, we saw how to resolve the
MySQL server has gone away error on a Linux system. The most common issue to cause this error is that your connection has simply timed out, but unexpected termination of the MySQL server, or a large payload can also make you get this error on your MySQL client system.