我正在尝试运行多线程脚本。
1个线程正常工作。但是,当我转到2个线程时,它将执行一些SQL命令,然后它将停止:
OperationalError: (2013, 'Lost connection to MySQL server during query')
第二个帖子也会停止:
OperationalError: (2006, 'MySQL server has gone away')
我已经阅读了很多关于此的文档,我做过的一些事情是:
max_allowed_packet
增加到64M。我的查询不是那么长(将100个URL插入数据库)connect_timeout
设为30 net_read_timeout
设为60 我的脚本是在python中并且非常冗长,但如果你正在寻找它,我不会关闭连接。
这两个游标都是由此代码生成的(在每个__init__
类的threading.Thread
部分中运行:
self.db = MySQLdb.connect(my details)
self.db.autocommit(True)
self.cursor = db.cursor()
日志错误文件如下:
140820 21:41:41 [Note] /usr/libexec/mysqld: Normal shutdown
140820 21:41:41 [Note] Event Scheduler: Purging the queue. 0 events
140820 21:41:41 InnoDB: Starting shutdown...
140820 21:41:44 InnoDB: Shutdown completed; log sequence number 0 44243
140820 21:41:44 [Note] /usr/libexec/mysqld: Shutdown complete
140820 21:41:44 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
140820 21:41:45 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
140820 21:41:45 [Warning] '--log' is deprecated and will be removed in a future release. Please use ''--general_log'/'--general_log_file'' instead.
140820 21:41:45 InnoDB: Initializing buffer pool, size = 8.0M
140820 21:41:45 InnoDB: Completed initialization of buffer pool
140820 21:41:45 InnoDB: Started; log sequence number 0 44243
140820 21:41:45 [Note] Event Scheduler: Loaded 0 events
140820 21:41:45 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.71-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
140820 21:45:36 [Note] /usr/libexec/mysqld: Normal shutdown
140820 21:45:36 [Note] Event Scheduler: Purging the queue. 0 events
140820 21:45:36 InnoDB: Starting shutdown...
140820 21:45:40 InnoDB: Shutdown completed; log sequence number 0 44243
140820 21:45:40 [Note] /usr/libexec/mysqld: Shutdown complete
140820 21:45:40 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
140820 21:45:41 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
140820 21:45:41 [Warning] '--log' is deprecated and will be removed in a future release. Please use ''--general_log'/'--general_log_file'' instead.
140820 21:45:41 InnoDB: Initializing buffer pool, size = 8.0M
140820 21:45:41 InnoDB: Completed initialization of buffer pool
140820 21:45:41 InnoDB: Started; log sequence number 0 44243
140820 21:45:41 [Note] Event Scheduler: Loaded 0 events
140820 21:45:41 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.71-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
任何想法为什么2个线程会引发问题,而不是1个线程?
非常感谢