我正试图在django env中处理MySQL的错误MySQL server has gone away
.
快速的解决方法是将全局wait_timeout
MySQL variable设置为一个巨大的值,但从长远来看,这将积累到许多开放的连接.
我想我会得到wait_timeout变量并以较小的间隔轮询服务器.实现这个后,我试着测试它,但没有得到错误.
我设置全局wait_timeout = 15甚至设置全局interactive_timeout = 15但连接拒绝消失.我确定我在15秒内以更大的间隔轮询数据库.
可能导致无法重现此错误的原因是什么?
最佳答案
运行以下脏和快速脚本并测试您的django项目或其他什么.我认为这不是一种优雅的方法,但效果很好.
原文链接:https://www.f2er.com/mysql/433045.htmlPHP
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" );
}
}
}
?>
这是结果.
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>