Working in an operations environment means that you get a lot of questions. There’s the inevitable troubleshooting tasks that go along with being a DBA. This is designed to be a quick reference post, much like my more in depth post in 2016 about timeouts. These typical error messages can create confusion and unneeded activities to diagnose. To aid my own process of elimination and those of others, here are three error messages every DBA should know by heart.
SQLSTATE[HY000]  Connection timed out
Plain and simple: this error means the client cannot connect to the server.
- The calling program is trying to connect to the wrong database server (one that it cannot reach).
- The database server is completely down (you’d get another error if the server and client actually made a connection).
- Firewall rules on either local servers or on a network resource is preventing the connection.
- Routes are misconfigured.
- The calling server has so many outbound connections that the MySQL client cannot create an outbound socket (think LSOF / netstat (lots of TIME_WAITed connections) ulimits / tcp_tw_reuse & recycle, etc).
- Anything else that might be preventing an actual TCP connection outbound to the server port (typically 3306).
SQLSTATE[HY000]  MySQL server has gone away
This error is typically related to server timeouts.
- an idle connection is hitting wait_timeout. wait_timeout concerns only idle sessions. sessions with running queries are not affected by this timeout.
- a running SELECT query with streaming cursor has not moved the cursor in [net_write_timeout] seconds
- a running bulk INSERT or UPDATE transaction has not written anything to the server within [net_read_timeout] seconds
- in rare cases interactive_timeout is being hit by an ad-hoc CLI client or other interactive program that respects the CLIENT_INTERACTIVE option to mysql_real_connect(). This is rare. Most of the time interactive_timeout = wait_timeout.
Keep in mind that if a DBA has mindfully set timeouts on the server that adjustments should be made to SESSION timeout variables within the calling program. In other words, don’t change server timeout settings just for one outlier or for some exceptional situation.
Also: This error can be “normal” in situations where the application opens a connection pool to the database and many connections in the pool are idle, hitting the wait timeout. In other words, in environments like this, SQLSTATE[HY000]  MySQL server has gone away can be a “non issue”. Work with developers to understand where in the code the error appears and collaborate on the correct solution, which may be to ensure the application’s MySQL connector or library is configured to reconnect.
SQLSTATE[HY000]  Lost connection to MySQL server during query
This error is exactly what it says.
- A mysql query was interrupted in the middle of the query, meaning it was
- killed by a backup utility on the server
- killed by pt-kill on the server,
- killed manually by a DBA on the server
- or some other situation by which the client thread lost the connection to the server (network issue between client and server).
- This error normally does not concern timeouts or settings on the server side.