python mysql 连接超时时间,通过python连接时,如何更改默认的Mysql连接超时?

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.

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 |

+----------------------------+----------+

How can I change the default timeout ?

解决方案

Do:

con.query('SET GLOBAL connect_timeout=28800')

con.query('SET GLOBAL wait_timeout=28800')

con.query('SET GLOBAL interactive_timeout=28800')

Parameter meaning (taken from MySQL Workbench in Navigator: Instance > Options File > Tab "Networking" > Section "Timeout Settings")

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

BTW: 28800 seconds are 8 hours, so for a 10 hour execution time these values should be actually higher.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值