纠结的SqlAlchemy: SQLError: (OperationalError) (2006, ‘MySQL server has gone away’)

纠结的SqlAlchemy: SQLError: (OperationalError) (2006, ‘MySQL server has gone away’)问题处理!

 

发现问题,应用启动后,第二天来访问就出现该问题。

 

在网上go了一下,发现是mysql长连接超时。

 

1. 查Mysql超时情况。

show variables like '%timeout%'

 

wait_timeout = 28800

 

mysql默认等待超时是8个小时

 

过了1晚上肯定有问题。

 

2. 查看sqlalchemy链接问题

 

create_engine(url,pool_size=20, max_overflow=-1, pool_recycle=true,echo=True) 

 

查了源码:

 

:param pool_recycle=-1: this setting causes the pool to recycle

        connections after the given number of seconds has passed. It

        defaults to -1, or no timeout. For example, setting to 3600

        means connections will be recycled after one hour. Note that

        MySQL in particular will disconnect automatically if no

        activity is detected on a connection for eight hours (although

        this is configurable with the MySQLDB connection itself and the

        server configuration as well).

 

 

pool_recycle is an integer number of seconds which to wait before 

   reopening a conneciton.  However, setting it to "True" is equivalent to 
          1 which means it will reopen connections constantly. 

 

        pool_recycle=true标识1秒重新链接一下

 

3. 修改后pool_recycle=7200

2小时链接一次

 

 

参考地址:

http://groups.google.com/group/sqlalchemy/browse_thread/thread/9412808e695168ea/c31f5c967c135be0?pli=1

        http://dba007.blog.51cto.com/2876338/788315

        http://hi.baidu.com/limodou/item/2d00f3333cc3b884c3cf29f7

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值