Skip to main content

MySQL (dagster-mysql)

dagster_mysql.MySQLResource ResourceDefinition

Resource for interacting with a MySQL database. Wraps an underlying mysql.connector connection.

Examples:

from dagster import Definitions, asset, EnvVar
from dagster_mysql import MySQLResource

@asset
def my_table(mysql: MySQLResource):
with mysql.get_connection() as conn:
with conn.cursor() as cur:
cur.execute("SELECT * FROM table;")

defs = Definitions(
assets=[my_table],
resources={
"mysql": MySQLResource(
host="localhost",
port=3306,
user="root",
password=EnvVar("MYSQL_PASSWORD")
)
}
)
class dagster_mysql.MySQLEventLogStorage

MySQL-backed event log storage.

Users should not directly instantiate this class; it is instantiated by internal machinery when dagster-webserver and dagster-graphql load, based on the values in the dagster.yaml file in $DAGSTER_HOME. Configuration of this class should be done by setting values in that file.

dagster.yaml


event_log_storage:
module: dagster_mysql.event_log
class: MySQLEventLogStorage
config:
mysql_db:
username: { username }
password: { password }
hostname: { hostname }
db_name: { db_name }
port: { port }

Note that the fields in this config are StringSource and IntSource and can be configured from environment variables.

class dagster_mysql.MySQLRunStorage

MySQL-backed run storage.

Users should not directly instantiate this class; it is instantiated by internal machinery when dagster-webserver and dagster-graphql load, based on the values in the dagster.yaml file in $DAGSTER_HOME. Configuration of this class should be done by setting values in that file.

dagster.yaml


run_storage:
module: dagster_mysql.run_storage
class: MySQLRunStorage
config:
mysql_db:
username: { username }
password: { password }
hostname: { hostname }
db_name: { database }
port: { port }

Note that the fields in this config are StringSource and IntSource and can be configured from environment variables.

class dagster_mysql.MySQLScheduleStorage

MySQL-backed run storage.

Users should not directly instantiate this class; it is instantiated by internal machinery when dagster-webserver and dagster-graphql load, based on the values in the dagster.yaml file in $DAGSTER_HOME. Configuration of this class should be done by setting values in that file.

dagster.yaml


schedule_storage:
module: dagster_mysql.schedule_storage
class: MySQLScheduleStorage
config:
mysql_db:
username: { username }
password: { password }
hostname: { hostname }
db_name: { db_name }
port: { port }

Note that the fields in this config are StringSource and IntSource and can be configured from environment variables.