airflow.providers.mysql.hooks.mysql
¶
This module allows to connect to a MySQL database.
Module Contents¶
Attributes¶
- class airflow.providers.mysql.hooks.mysql.MySqlHook(*args, **kwargs)[source]¶
Bases:
airflow.hooks.dbapi.DbApiHook
Interact with MySQL.
You can specify charset in the extra field of your connection as
{"charset": "utf8"}
. Also you can choose cursor as{"cursor": "SSCursor"}
. Refer to the MySQLdb.cursors for more details.Note: For AWS IAM authentication, use iam in the extra connection parameters and set it to true. Leave the password field empty. This will use the "aws_default" connection to get the temporary token unless you override in extras. extras example:
{"iam":true, "aws_conn_id":"my_aws_conn"}
- Parameters
schema -- The MySQL database schema to connect to.
connection -- The MySQL connection id used for MySQL credentials.
- set_autocommit(self, conn, autocommit)[source]¶
The MySQLdb (mysqlclient) client uses an autocommit method rather than an autocommit property to set the autocommit setting
- Parameters
conn (MySQLConnectionTypes) -- connection to set autocommit setting
autocommit (bool) -- autocommit setting
- Return type
None
- get_autocommit(self, conn)[source]¶
The MySQLdb (mysqlclient) client uses a get_autocommit method rather than an autocommit property to get the autocommit setting
- Parameters
conn (MySQLConnectionTypes) -- connection to get autocommit setting from.
- Returns
connection autocommit setting
- Return type
- get_conn(self)[source]¶
Establishes a connection to a mysql database by extracting the connection configuration from the Airflow connection.
Note
By default it connects to the database via the mysqlclient library. But you can also choose the mysql-connector-python library which lets you connect through ssl without any further ssl parameters required.
- Returns
a mysql connection object
- Return type
MySQLConnectionTypes
- get_iam_token(self, conn)[source]¶
Uses AWSHook to retrieve a temporary password to connect to MySQL Port is required. If none is provided, default 3306 is used
- bulk_load_custom(self, table, tmp_file, duplicate_key_handling='IGNORE', extra_options='')[source]¶
A more configurable way to load local data from a file into the database.
Warning
According to the mysql docs using this function is a security risk. If you want to use it anyway you can do so by setting a client-side + server-side option. This depends on the mysql client library used.
- Parameters
table (str) -- The table were the file will be loaded into.
tmp_file (str) -- The file (name) that contains the data.
duplicate_key_handling (str) --
Specify what should happen to duplicate data. You can choose either IGNORE or REPLACE.
extra_options (str) --
More sql options to specify exactly how to load the data.