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

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Can#39;t Create Entity Data Model - using MySql and EF6(无法创建实体数据模型 - 使用 MySql 和 EF6)
MySQL select with CONCAT condition(MySQL选择与CONCAT条件)
Capitalize first letter of each word, in existing table(将现有表格中每个单词的首字母大写)
How to retrieve SQL result column value using column name in Python?(如何在 Python 中使用列名检索 SQL 结果列值?)
Update row with data from another row in the same table(使用同一表中另一行的数据更新行)
Exporting results of a Mysql query to excel?(将 Mysql 查询的结果导出到 excel?)