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

2021-11-20 00:00:00 python corpus mysql

我使用 python 连接到 mysql 数据库 con = _mysql.connect('localhost', 'dell-pc', '', 'test')我编写的程序完全执行需要很多时间,即大约 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    |
+----------------------------+----------+

如何更改默认超时时间?

How can I change the default timeout ?

推荐答案

做:

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

参数含义(取自 MySQL Workbench in Navigator:Instance > Options File > Tab Networking" > Section Timeout Settings")

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.

相关文章