Deliberately getting the error "MySQL server is gone"

I am trying to handle a MySQL error MySQL server has gone awayin django env.

A quick fix was to set the global wait_timeoutMySQL variable to a huge value, but eventually many open connections would accumulate.

I decided that I would get the variable wait_timeoutand poll the server at shorter intervals. After implementing this, I tried to test it, but could not get the error.

I set global wait_timeout=15and even set global interactive_timeout=15, but the connection does not disappear. I am sure that I am polling the database at larger intervals than 15 seconds.

What could be the reason for the inability to recreate this error?

+5
source share
1 answer

Run under a dirty and fast script and check out the django project or something else. 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> 
+4
source

All Articles