# 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=None, user=None, password=None, host=None, port=3306, query=None, commit=False, charset="utf8mb4", ssl=None, **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)
  • ssl (dict, optional): A dict of arguments similar to mysql_ssl_set()’s parameters used for establishing encrypted connections using SSL
  • **kwargs (Any, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.mysql.mysql.MySQLExecute.run

(db_name=None, user=None, password=None, host=None, port=None, query=None, commit=None, charset=None, ssl=None)[source]

Task run method. Executes a query against 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")
  • ssl (dict, optional): A dict of arguments similar to mysql_ssl_set()’s parameters used for establishing encrypted connections using SSL. To connect with SSL, at least ssl_ca, ssl_cert, and ssl_key must be specified.
Returns:
  • executed (int): number of affected rows
Raises:
  • pymysql.MySQLError



# MySQLFetch

class

prefect.tasks.mysql.mysql.MySQLFetch

(db_name=None, user=None, password=None, host=None, port=3306, fetch="one", fetch_count=10, query=None, commit=False, charset="utf8mb4", cursor_type="cursor", ssl=None, **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"
  • cursor_type (Union[str, Callable], optional): The cursor type to use. Can be 'cursor' (the default), 'dictcursor', 'sscursor', 'ssdictcursor', or a full cursor class.
  • ssl (dict, optional): A dict of arguments similar to mysql_ssl_set()’s parameters used for establishing encrypted connections using SSL. To connect with SSL, at least ssl_ca, ssl_cert, and ssl_key must be specified.
  • **kwargs (Any, optional): additional keyword arguments to pass to the Task constructor

methods:                                                                                                                                                       

prefect.tasks.mysql.mysql.MySQLFetch.run

(db_name=None, user=None, password=None, host=None, port=None, fetch=None, fetch_count=None, query=None, commit=None, charset=None, cursor_type=None, ssl=None)[source]

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

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"
  • cursor_type (Union[str, Callable], optional): The cursor type to use. Can be 'cursor' (the default), 'dictcursor', 'sscursor', 'ssdictcursor', or a full cursor class.
  • ssl (dict, optional): A dict of arguments similar to mysql_ssl_set()’s parameters used for establishing encrypted connections using SSL
Returns:
  • results (tuple or list of tuples): records from provided query
Raises:
  • pymysql.MySQLError



This documentation was auto-generated from commit ffa9a6c
on February 1, 2023 at 18:44 UTC