用于 Python 的 MySQL 连接器 [英] MySQL Connector for Python
本文介绍了用于 Python 的 MySQL 连接器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Python 中使用 mysql.connector
.下面是我的连接参数.如何设置超时或增加默认超时?
I am using mysql.connector
for Python. Below are my connection parameters. How can I set a timeout or increase the default timeout?
class Config(object):
"""Configure me so examples work
Use me like this:
mysql.connector.Connect(**Config.dbinfo())
"""
HOST = dbhost
DATABASE = dbdatabase
USER = dbusername
PASSWORD = dbpassword
PORT = 3306
CHARSET = 'utf8'
UNICODE = True
WARNINGS = True
@classmethod
def dbinfo(cls):
return {
'host': cls.HOST,
'port': cls.PORT,
'database': cls.DATABASE,
'user': cls.USER,
'password': cls.PASSWORD,
'charset': cls.CHARSET,
'use_unicode': cls.UNICODE,
'get_warnings': cls.WARNINGS,
}
推荐答案
根据 官方文档中的MySQL Connector/Python :: 6 Connector/Python Connection Arguments:
要为连接设置超时值,请使用 connection_timeout
.
To set a timeout value for connections, use
connection_timeout
.
这篇关于用于 Python 的 MySQL 连接器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文