# MySQL Tasks


This module contains a collection of tasks for interacting with MySQL databases via the pymysql library.

# MySQLExecute

class

prefect.tasks.mysql.mysql.MySQLExecute

(db_name, user, password, host, port=3306, query=None, commit=False, charset="utf8mb4", **kwargs)[source]

Task for executing a query against a MySQL database.

Args:

  • db_name (str): name of MySQL database
  • user (str): user name used to authenticate
  • password (str): password used to authenticate
  • host (str): database host address
  • port (int, optional): port used to connect to MySQL database, defaults to 3307 if not provided
  • query (str, optional): query to execute against database
  • commit (bool, optional): set to True to commit transaction, defaults to false
  • charset (str, optional): charset you want to use (defaults to utf8mb4)
  • **kwargs (Any, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.mysql.mysql.MySQLExecute.run

(query, commit=False, charset="utf8mb4")[source]

Task run method. Executes a query against MySQL database.

Args:

  • query (str, optional): query to execute against database
  • commit (bool, optional): set to True to commit transaction, defaults to False
  • charset (str, optional): charset of the query, defaults to "utf8mb4"
Returns:
  • executed (int): number of affected rows
Raises:
  • pymysql.MySQLError



# MySQLFetch

class

prefect.tasks.mysql.mysql.MySQLFetch

(db_name, user, password, host, port=3306, fetch="one", fetch_count=10, query=None, commit=False, charset="utf8mb4", **kwargs)[source]

Task for fetching results of query from MySQL database.

Args:

  • db_name (str): name of MySQL database
  • user (str): user name used to authenticate
  • password (str): password used to authenticate
  • host (str): database host address
  • port (int, optional): port used to connect to MySQL database, defaults to 3307 if not provided
  • fetch (str, optional): one of "one" "many" or "all", used to determine how many results to fetch from executed query
  • fetch_count (int, optional): if fetch = 'many', determines the number of results to fetch, defaults to 10
  • query (str, optional): query to execute against database
  • commit (bool, optional): set to True to commit transaction, defaults to false
  • charset (str, optional): charset of the query, defaults to "utf8mb4"
  • **kwargs (Any, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.mysql.mysql.MySQLFetch.run

(query, fetch="one", fetch_count=10, commit=False, charset="utf8mb4")[source]

Task run method. Executes a query against MySQL database and fetches results.

Args:

  • fetch (str, optional): one of "one" "many" or "all", used to determine how many results to fetch from executed query
  • fetch_count (int, optional): if fetch = 'many', determines the number of results to fetch, defaults to 10
  • query (str, optional): query to execute against database
  • commit (bool, optional): set to True to commit transaction, defaults to false
  • charset (str, optional): charset of the query, defaults to "utf8mb4"
Returns:
  • results (tuple or list of tuples): records from provided query
Raises:
  • pymysql.MySQLError



This documentation was auto-generated from commit 4a4acb5
on October 23, 2020 at 16:22 UTC