How can I change the default Mysql connection timeout when connecting through python?(通过python连接时如何更改默认的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.
这篇关于通过python连接时如何更改默认的Mysql连接超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过python连接时如何更改默认的Mysql连接超时?


基础教程推荐
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01