blob: ebafa133603b3a9868ff8af78cd07cf3afb0942d [file] [log] [blame]
:mod:`airflow.hooks.mysql_hook`
===============================
.. py:module:: airflow.hooks.mysql_hook
Module Contents
---------------
.. py:class:: MySqlHook(*args, **kwargs)
Bases: :class:`airflow.hooks.dbapi_hook.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 the
"aws_default" connection to get the temporary token unless you override
in extras.
extras example: ``{"iam":true, "aws_conn_id":"my_aws_conn"}``
.. attribute:: conn_name_attr
:annotation: = mysql_conn_id
.. attribute:: default_conn_name
:annotation: = mysql_default
.. attribute:: supports_autocommit
:annotation: = True
.. method:: set_autocommit(self, conn, autocommit)
MySql connection sets autocommit in a different way.
.. method:: get_autocommit(self, conn)
MySql connection gets autocommit in a different way.
:param conn: connection to get autocommit setting from.
:type conn: connection object.
:return: connection autocommit setting
:rtype: bool
.. method:: get_conn(self)
Returns a mysql connection object
.. method:: get_uri(self)
.. method:: bulk_load(self, table, tmp_file)
Loads a tab-delimited file into a database table
.. method:: bulk_dump(self, table, tmp_file)
Dumps a database table into a tab-delimited file
.. staticmethod:: _serialize_cell(cell, conn)
MySQLdb converts an argument to a literal
when passing those separately to execute. Hence, this method does nothing.
:param cell: The cell to insert into the table
:type cell: object
:param conn: The database connection
:type conn: connection object
:return: The same cell
:rtype: object
.. method:: get_iam_token(self, conn)
Uses AWSHook to retrieve a temporary password to connect to MySQL
Port is required. If none is provided, default 3306 is used
.. method:: bulk_load_custom(self, table, tmp_file, duplicate_key_handling='IGNORE', extra_options='')
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 <https://dev.mysql.com/doc/refman/8.0/en/load-data-local.html>`_.
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.
:param table: The table were the file will be loaded into.
:type table: str
:param tmp_file: The file (name) that contains the data.
:type tmp_file: str
:param duplicate_key_handling: Specify what should happen to duplicate data.
You can choose either `IGNORE` or `REPLACE`.
.. seealso::
https://dev.mysql.com/doc/refman/8.0/en/load-data.html#load-data-duplicate-key-handling
:type duplicate_key_handling: str
:param extra_options: More sql options to specify exactly how to load the data.
.. seealso:: https://dev.mysql.com/doc/refman/8.0/en/load-data.html
:type extra_options: str