I'm trying to cope with MySQL's error MySQL server has gone away
in a django env.
The quick workaround was to set the global wait_timeout
MySQL variable to a huge value, but in the long run this would accumulate to many open connections.
I figured I'll get the wait_timeout
variable and poll the server in smaller intervals. After implementing this I tried to test it but am failing to get the error.
I set global wait_timeout=15
and even set global interactive_timeout=15
but the connection refuses to disappear. I'm sure I'm polling the database in larger intervals than 15sec.
What could be the cause for not being able to recreate this error?
Run below dirty-and-quick script and test your django project or whatever. I think this is not an elegant approach, but it works well.
<?php
mysql_connect( "127.0.0.1", "id", "pw" ); // should be changed to yours
while(1)
{
$r = mysql_query( "SHOW PROCESSLIST" );
while( $d = mysql_fetch_row( $r ) )
{
if( $d[7] != "SHOW PROCESSLIST" )
{
mysql_query( "KILL ". $d[0] );
echo( $d[0]." was killed.\n" );
}
}
}
?>
And here is the result.
mysql> select * from foo;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 337
Current database: test
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 338
Current database: test
ERROR 2006 (HY000): MySQL server has gone away
mysql>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With