By default, the server closes the connection after eight hours if nothing has happened. You can change the time limit by setting the
wait_timeout
variable when you start mysqld. See Section 5.1.3, “Server System Variables”.If you have a script, you just have to issue the query again for the client to do an automatic reconnection. This assumes that you have automatic reconnection in the client enabled (which is the default for the
mysql
command-line client).Some other common reasons for the
MySQL server has gone away
error are:- You (or the db administrator) has killed the running thread with a
KILL
statement or a mysqladmin killcommand. - You tried to run a query after closing the connection to the server. This indicates a logic error in the application that should be corrected.
- A client application running on a different host does not have the necessary privileges to connect to the MySQL server from that host.
- You got a timeout from the TCP/IP connection on the client side. This may happen if you have been using the commands:
mysql_options(..., MYSQL_OPT_READ_TIMEOUT,...)
ormysql_options(..., MYSQL_OPT_WRITE_TIMEOUT,...)
. In this case increasing the timeout may help solve the problem. - You have encountered a timeout on the server side and the automatic reconnection in the client is disabled (the
reconnect
flag in theMYSQL
structure is equal to 0) - You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld receives a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection. If you need big queries (for example, if you are working with big
BLOB
columns), you can increase the query limit by setting the server'smax_allowed_packet
variable, which has a default value of 1MB. You may also need to increase the maximum packet size on the client end. More information on setting the packet size is given inSection C.5.2.10, “Packet too large
”.AnINSERT
orREPLACE
statement that inserts a great many rows can also cause these sorts of errors. Either one of these statements sends a single request to the server irrespective of the number of rows to be inserted; thus, you can often avoid the error by reducing the number of rows sent perINSERT
orREPLACE
. - You also get a lost connection if you are sending a packet 16MB or larger if your client is older than 4.0.8 and your server is 4.0.8 and above, or the other way around.
- It is also possible to see this error if host name lookups fail (for example, if the DNS server on which your server or network relies goes down). This is because MySQL is dependent on the host system for name resolution, but has no way of knowing whether it is working—from MySQL's point of view the problem is indistinguishable from any other network timeout.You may also see the
MySQL server has gone away
error if MySQL is started with the--skip-networking
option.
No comments:
Post a Comment