zoukankan      html  css  js  c++  java
  • (2006, 'MySQL server has gone away') 错误解决 dba007的空间 51CTO技术博客

    (2006, 'MySQL server has gone away') 错误解决 - dba007的空间 - 51CTO技术博客

    (2006, 'MySQL server has gone away') 错误解决

    2012-02-24 10:30:14

     在使用 Python + MySQLdb 部署项目的时候,执行计划任务报错

      OperationalError (2006, 'MySQL server has gone away')
     
     
    解决办法1: 原因是由于长时间的执行批量的MYSQL语句造成,修改/etc/my.cnf
    在[mysqld]段落加入wait_timeout=90000 示例文件内容如下:
      [mysqld]
      datadir=/var/lib/mysql
      socket=/var/lib/mysql/mysql.sock
      # Default to using old password format for compatibility with mysql 3.x
      # clients (those using the mysqlclient10 compatibility package).
      old_passwords=1
      # 修正 OperationalError: (2006, 'MySQL server has gone away') 错误
      wait_timeout=100000
          
      其他省略.......
    然后 重启mysql服务,再次访问问题页面,没有再出现如上问题,问题得到暂时解决
     
     
    解决办法2: 修改数据库连接代码 使用mysql ping来检查连接,实现超时自动重新连接
      #/usr/bin/env python
      import MySQLdb
      con=MySQLdb.Connect( host="foobar.com",
                           port=3306,
                           user="loginname",
                           passwd="loginpassword",
                           db="foobar")
      con.ping(True)
      cur=con.cursor()
    推荐使用第2种解决方法,从代码彻底解决!
  • 相关阅读:
    抽象类abstract
    final关键字特点
    继承ExtendsFour
    继承(继承中构造方法的关系)
    继承ExtendsTwo-super&this
    继承ExtendsOne
    静态
    构造方法与setXxx方法
    15.8
    15.7
  • 原文地址:https://www.cnblogs.com/lexus/p/2532825.html
Copyright © 2011-2022 走看看