Irecently discovered that a sql query that was running fine earlier is now timing out after 60 seconds and throwing an error. The query is slow but runs as part of a nightly job so that's not a problem in itself (so please don't suggest I optimize it).
I'm able to reproduce the error consistently by running "select SLEEP(120);" from PHP as shown below. However, running the same statement from a MySQL client is successful (returns 0). I've tried adjusting wait_timeout (set to 28800), but have had no luck. I've also rebooted both the db server and machine itself.
When I ran into this problem, it wasn't caused by wait_timeout (which was set to the default 8 hours) but by max_allowed_packet with a large INSERT statement. Changing max_allowed_packet from PHP had no effect, but when I changed it in the mysqld section of /etc/my.cnf and restarted the MySQL server, the problem disappeared.
I had two scripts running, both doing rather slow queries. One of them locked a table and the other had to wait. The one that was waiting had default_socket_timeout = 300. Eventually it quit with "MySQL server has gone away". However, the mysql process list continued to show both query, the slow one still running and the other locked and waiting.
I was having trouble on a database restore using mysqldumper (php program). I was able to get it working by changing the "mssql.timeout" setting in the php.ini. It was defaulted to 60 and I changed it to 300.
It happens if the connection was open for quite sometime but no action was done in the MySQL server. In that case, connection timeout occurs with the error "MySQL server has gone away". The answers above may work and may not work. Even the accepted answer did not work for me. So I tried a trick and it worked fine for me. Logically, in order to avoid this error, we have to keep the MySQL connection running or in short, keep it alive. Assume that we are trying to Bulk insert 250k records. Generally it takes time to create parse data from somewhere and make Bulk query and then insert. In this scenario, most of us use a loop to create the SQL string. So let's count the iteration number and make a dummy database call after a certain iteration. It will keep the connection alive.
By my experiences when it happens on light queries there is a way to solve the problem. It seems when you start or restart mysql after apache this problem starts to appear and the source of the problem is confused open sockets in the php process. To solve it:
Gone In 60 Seconds, which refers to the length of time it takes a professional thief to make your car... his car, is a remake of the 1974 cult classic, made famous by its spectacular 40 minute police chase during which 93 cars were destroyed.
The updated story finds legendary car thief and auto aficionado, Randall "Memphis" Raines, being forced back into a life of crime to save the life of his kid brother, who has become entangled in a dangerous high-stakes caper. With more star power and horsepower than Hollywood has seen in years, this fast-paced action thriller promises to blow the covers off the valves at the summer box office.
To commemorate the Jerry Bruckheimer production of Gone In 60 Seconds, HOT WHEELS COLLECTIBLES' has replicated four hot cars from the film, including a classic '49 Merc, a striking Dodge Viper GTS, a custom '67 Mustang and a cab-over truck! Don't wait to get your hands on this highly collectible car set , because it too could be gone in 60 seconds.
3a8082e126