awswrangler.mysql.connect(connection: str | None = None, secret_id: str | None = None, catalog_id: str | None = None, dbname: str | None = None, boto3_session: boto3.Session | None = None, read_timeout: int | None = None, write_timeout: int | None = None, connect_timeout: int = 10, cursorclass: type['pymysql.cursors.Cursor'] | None = None) pymysql.connections.Connection[Any]

Return a pymysql connection from a Glue Catalog Connection or Secrets Manager.


You MUST pass a connection OR secret_id. Here is an example of the secret structure in Secrets Manager: { “host”:””, “username”:”test”, “password”:”test”, “engine”:”mysql”, “port”:”3306”, “dbname”: “mydb” # Optional }


It is only possible to configure SSL using Glue Catalog Connection. More at:


Consider using SSCursor cursorclass for queries that return a lot of data. More at:

  • connection (str) – Glue Catalog Connection name.

  • secret_id (str, optional) – Specifies the secret containing the connection details 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 (str, optional) – 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 (int, optional) – The timeout for reading from the connection in seconds (default: None - no timeout). This parameter is forward to pymysql.

  • write_timeout (int, optional) – The timeout for writing to the connection in seconds (default: None - no timeout) This parameter is forward to pymysql.

  • connect_timeout (int) – Timeout before throwing an exception when connecting. (default: 10, min: 1, max: 31536000) This parameter is forward to pymysql.

  • cursorclass (Cursor) – Cursor class to use, e.g. SSCursor; defaults to pymysql.cursors.Cursor


pymysql connection.

Return type:



>>> 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()