Search code examples
pythonmysqlmysql-connector-python

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 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,
            }

Solution

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

    To set a timeout value for connections, use connection_timeout.