How to configure a MySQL Datasource

This guide shows how to connect to a MySql Datasource. Great Expectations uses SqlAlchemy to connect to MySQL.

Prerequisites: This how-to guide assumes you have already:

Steps

  1. Install the required modules

    If you have not already done so, install required modules for connecting to mysql.

    pip install sqlalchemy
    pip install PyMySQL
    
  2. Run datasource new

    From the command line, run:

    great_expectations datasource new
    
  3. Choose “Relational database (SQL)”

    What data would you like Great Expectations to connect to?
        1. Files on a filesystem (for processing with Pandas or Spark)
        2. Relational database (SQL)
    : 2
    
  4. Choose MySQL

    Which database backend are you using?
        1. MySQL
        2. Postgres
        3. Redshift
        4. Snowflake
        5. BigQuery
        6. other - Do you have a working SQLAlchemy connection string?
    : 1
    
  5. Give your Datasource a name

    When prompted, provide a custom name for your Snowflake data source, or hit Enter to accept the default.

    Give your new Datasource a short name.
     [my_mysql_db]:
    
  6. Enter connection information

    When prompted, provide a custom name for your new Datasource, or hit Enter to accept the default.

    Next, we will configure database credentials and store them in the `my_mysql_db` section
    of this config file: great_expectations/uncommitted/config_variables.yml:
    
    What is the host for the MySQL connection? [localhost]:
    What is the port for the MySQL connection? [3306]:
    What is the username for the MySQL connection? []: root
    What is the password for the MySQL connection?:
    What is the database name for the MySQL connection? []: test_ci
    Attempting to connect to your database. This may take a moment...
    
  7. Save your new configuration

    Great Expectations will now add a new Datasource 'my_mysql_db' to your deployment, by adding this entry to your great_expectations.yml:
    
      my_mysql_db:
        credentials: ${my_mysql_db}
        data_asset_type:
          class_name: SqlAlchemyDataset
          module_name: great_expectations.dataset
        class_name: SqlAlchemyDatasource
        module_name: great_expectations.datasource
    
    The credentials will be saved in uncommitted/config_variables.yml under the key 'my_mysql_db'
    

Additional notes

Comments