How do I resolve the error "MySQL server has gone away" when connecting to my Amazon RDS MySQL DB instance?
Last updated: 2019-12-20
I tried to query an Amazon Relational Database Service (Amazon RDS) DB instance that is running MySQL, and I received one of the following error messages: "MySQL server has gone away" or "Lost connection to server during query."
If the server timed out and closed the connection, you can receive one of the following errors:
- CR_SERVER_GONE_ERROR - The client couldn't send a question to the server.
- CR_SERVER_LOST - The client didn't get an error when writing to the server, but the client didn't get a full answer (or any answer) to the question.
For more information, see the MySQL documentation for MySQL server has gone away.
See the following causes for and related resolutions for these errors:
- If a connection is idle for too long, the connection might be terminated incorrectly from the client. To resolve this issue, verify that application timeouts are shorter than the MySQL timeouts, and be sure that your applications close idle connections.
- If a connection times out, increase the timeouts for MySQL by increasing the wait_timeout and interactive_timeout parameters by using a custom parameter group. For more information, see Working with DB Parameter Groups.
- If the query that is generating the error is retrieving a large data set, increase the max_allowed_packet size parameter by using a custom parameter group. For more information, see Modifying Parameters in a DB Parameter Group.
- If the error occurs only when returning large data sets, the client might be using a large MTU value of 9001. To resolve this issue, reduce the client TCP/IP MTU value. For information on changing your client MTU value, see Configuring the MTU of an Instance.
- If any init_connect parameters are set to a value that doesn't allow the parameter to be processed, associated client connections can fail. Be sure that all init_connect parameters are processed correctly. Be sure that users have EXECUTE permissions for any procedures referenced as an init_connect parameter.
- If all connections are dropping at the same time, confirm that other connections are still working when this issue occurs. To resolve this issue, verify the MySQL DB instance is not crashing or failing over by viewing Amazon RDS events and reviewing your MySQL error logs.