通过python连接时,如何更改默认的Mysql连接超时? [英] How can I change the default Mysql connection timeout when connecting through python?
问题描述
我使用python con = _mysql.connect('localhost', 'dell-pc', '', 'test')
连接到mysql数据库
我编写的程序需要花费大量时间才能完全执行,即大约需要10个小时.实际上,我正在尝试从语料库中读取不同的词.
读取完成后,出现超时错误.
I connected to a mysql database using python con = _mysql.connect('localhost', 'dell-pc', '', 'test')
The program that I wrote takes a lot of time in full execution i.e. around 10 hours. Actually, I am trying to read distinct words from a corpus.
After reading was finished there was a timeout error.
我检查了Mysql的默认超时:
I checked Mysql default timeouts which were:
+----------------------------+----------+
| Variable_name | Value |
+----------------------------+----------+
| connect_timeout | 10 |
| delayed_insert_timeout | 300 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 28800 |
| lock_wait_timeout | 31536000 |
| net_read_timeout | 30 |
| net_write_timeout | 60 |
| slave_net_timeout | 3600 |
| wait_timeout | 28800 |
+----------------------------+----------+
如何更改默认超时?
推荐答案
执行:
con.query('SET GLOBAL connect_timeout=28800')
con.query('SET GLOBAL wait_timeout=28800')
con.query('SET GLOBAL interactive_timeout=28800')
参数含义(取自Navigator中的MySQL Workbench:实例>选项文件>选项卡网络">超时设置"部分)
Parameter meaning (taken from MySQL Workbench in Navigator: Instance > Options File > Tab "Networking" > Section "Timeout Settings")
- connect_timeout :mysqld服务器等待连接数据包的秒数,然后以错误的握手"响应
- interactive_timeout ,服务器在关闭交互式连接之前等待其活动的秒数
- wait_timeout ,服务器在关闭连接之前等待连接活动的秒数
- connect_timeout: Number of seconds the mysqld server waits for a connect packet before responding with 'Bad handshake'
- interactive_timeout Number of seconds the server waits for activity on an interactive connection before closing it
- wait_timeout Number of seconds the server waits for activity on a connection before closing it
顺便说一句:28800秒是8个小时,因此在10个小时的执行时间内,这些值实际上应该更高.
BTW: 28800 seconds are 8 hours, so for a 10 hour execution time these values should be actually higher.
这篇关于通过python连接时,如何更改默认的Mysql连接超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!