awswrangler.mysql.connect

awswrangler.mysql.connect(connection: Optional[str] = None, secret_id: Optional[str] = None, catalog_id: Optional[str] = None, dbname: Optional[str] = None, boto3_session: Optional[boto3.session.Session] = None, read_timeout: Optional[int] = None, write_timeout: Optional[int] = None, connect_timeout: int = 10) → pymysql.connections.Connection

Return a pymysql connection from a Glue Catalog Connection.

https://pymysql.readthedocs.io

Parameters
  • connection (str) – Glue Catalog Connection name.

  • secret_id (Optional[str]:) – Specifies the secret containing the version that you want to retrieve. You can specify either the Amazon Resource Name (ARN) or the friendly name of the secret.

  • catalog_id (str, optional) – The ID of the Data Catalog. If none is provided, the AWS account ID is used by default.

  • dbname (Optional[str]) – Optional database name to overwrite the stored one.

  • boto3_session (boto3.Session(), optional) – Boto3 Session. The default boto3 session will be used if boto3_session receive None.

  • read_timeout (Optional[int]) – The timeout for reading from the connection in seconds (default: None - no timeout). This parameter is forward to pymysql. https://pymysql.readthedocs.io/en/latest/modules/connections.html

  • write_timeout (Optional[int]) – The timeout for writing to the connection in seconds (default: None - no timeout) This parameter is forward to pymysql. https://pymysql.readthedocs.io/en/latest/modules/connections.html

  • connect_timeout (int) – Timeout before throwing an exception when connecting. (default: 10, min: 1, max: 31536000) This parameter is forward to pymysql. https://pymysql.readthedocs.io/en/latest/modules/connections.html

Returns

pymysql connection.

Return type

pymysql.connections.Connection

Examples

>>> import awswrangler as wr
>>> con = wr.mysql.connect("MY_GLUE_CONNECTION")
>>> with con.cursor() as cursor:
>>>     cursor.execute("SELECT 1")
>>>     print(cursor.fetchall())
>>> con.close()