MySQL Connection

The MySQL connection type provides connection to a MySQL database.

Configuring the Connection

Host (required)

The host to connect to.

Schema (optional)

Specify the schema name to be used in the database.

Login (required)

Specify the user name to connect.

Password (required)

Specify the password to connect.

Extra (optional)

Specify the extra parameters (as json dictionary) that can be used in MySQL connection. Note that you can choose the client to connect to the database by setting the client extra field.

For mysqlclient (default) the following extras are supported:

  • charset: specify charset of the connection

  • cursor: one of sscursor, dictcursor, ssdictcursor . Specifies cursor class to be used

  • unix_socket: UNIX socket used instead of the default socket.

  • ssl: Dictionary of SSL parameters that control connecting using SSL. Those parameters are server specific and should contain ca, cert, key, capath, cipher parameters. See MySQLdb docs for details. Note that to be useful in URL notation, this parameter might also be a string where the SSL dictionary is a string-encoded JSON dictionary.

Example “extras” field:

   "charset": "utf8",
   "cursor": "sscursor",
   "unix_socket": "/var/socket",
   "ssl": {
     "cert": "/tmp/client-cert.pem",
     "ca": "/tmp/server-ca.pem",
     "key": "/tmp/client-key.pem"


   "charset": "utf8",
   "cursor": "sscursor",
   "unix_socket": "/var/socket",
   "ssl": "{\"cert\": \"/tmp/client-cert.pem\", \"ca\": \"/tmp/server-ca.pem\", \"key\": \"/tmp/client-key.pem\"}"

When specifying the connection as URI (in AIRFLOW_CONN_{CONN_ID} variable) you should specify it following the standard syntax of DB connections - where extras are passed as parameters of the URI. Note that all components of the URI should be URL-encoded.

For example:



If encounter UnicodeDecodeError while working with MySQL connection, check the charset defined is matched to the database charset.

For mysql-connector-python no extras are supported:

In both cases, when you want to use LOAD DATA LOCAL INFILE SQL commands of MySQl, you need to create the Hook with “local_infile” parameter set to True.

Was this entry helpful?