Skip to content Skip to sidebar Skip to footer

Mysql Connector For Python

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 exa

Solution 1:

According to MySQL Connector/Python :: 6 Connector/Python Connection Arguments in the official documentation:

To set a timeout value for connections, use connection_timeout.

Solution 2:

I found something here: http://dev.mysql.com/doc/refman/5.5/en/connector-python-connectargs.html I think you are looking for the parameter connection_timeout (connect_timeout*)

Solution 3:

If you are using mysql.connector.connect to connect with DB you can simply use connection_timeout parameter to define a timeout externally make sure value given will be in seconds instead of milliseconds.

conn = mysql.connector.connect(
    pool_name=pool['name'], 
    pool_size=pool['size'],
    host=config['host'], 
    port=config['port'], 
    user=config['user'],
    passwd=config['passwd'],
    db=config['db'],
    charset=config['charset'], 
    use_unicode=True,
    connection_timeout=10
)

Solution 4:

This works for me:

conn = mysql.connector.connect(
    pool_name=pool['name'], 
    pool_size=pool['size'],
    host=config['host'], 
    port=config['port'], 
    user=config['user'],
    passwd=config['passwd'],
    db=config['db'],
    charset=config['charset'], 
    use_unicode=True,
    connect_timeout=1000
)

If you use MySQLdb:

conn = MySQLdb.connect(
    host=config['host'], 
    port=config['port'], 
    user=config['user'], 
    passwd=config['passwd'],
    db=config['db'], 
    charset=config['charset'], 
    use_unicode=True,
    connect_timeout=1000
)

Post a Comment for "Mysql Connector For Python"