LogoLogo
  • Welcome to Gretel!
  • Gretel Basics
    • Getting Started
      • Quickstart
      • Blueprints
      • Use Case Examples
      • Environment Setup
        • Console
        • SDK
      • Projects
      • Inputs and Outputs
      • Gretel Connectors
        • Object Storage
          • Amazon S3
          • Google Cloud Storage
          • Azure Blob
        • Database
          • MySQL
          • PostgreSQL
          • MS SQL Server
          • Oracle Database
        • Data Warehouse
          • Snowflake
          • BigQuery
          • Databricks
        • Gretel Project
    • Release Notes
      • Platform Release Notes
        • May 2025
        • April 2025
        • March 2025
        • February 2025
        • January 2025
        • December 2024
        • November 2024
        • October 2024
        • September 2024
        • August 2024
        • July 2024
        • June 2024
      • Console Release Notes
        • January 2025
        • December 2024
        • November 2024
        • October 2024
        • September 2024
        • August 2024
      • Python SDKs
  • Create Synthetic Data
    • Gretel Safe Synthetics
      • Transform
        • Reference
        • Examples
        • Supported Entities
      • Synthetics
        • Gretel Tabular Fine-Tuning
        • Gretel Text Fine-Tuning
        • Gretel Tabular GAN
        • Benchmark Report
        • Privacy Protection
      • Evaluate
        • Synthetic Quality & Privacy Report
        • Tips to Improve Synthetic Data Quality
        • Data Privacy 101
      • SDK
    • Gretel Data Designer
      • Getting Started with Data Designer
      • Define your Data Columns
        • Column Types
        • Add Constraints to Columns
        • Custom Model Configurations
        • Upload Files as Seeds
      • Building your Dataset
        • Seeding your Dataset
        • Generating Data
      • Generate Realistic Personal Details
      • Structured Outputs
      • Code Validation
      • Data Evaluation
      • Magic Assistance
      • Using Jinja Templates
  • Gretel Playground [Legacy]
    • Getting Started
    • Prompts Tips & Best Practices
    • FAQ
    • SDK Examples
    • Tutorials
    • Videos
    • Gretel Playground [Legacy] Inference API
    • Batch Job SDK
  • Reference
    • Gretel's Python Client
    • Gretel’s Open Source Synthetic Engine
    • Gretel’s REST API
    • Homepage
    • Model Suites
Powered by GitBook
On this page
  • Getting Started
  • Create a Connection
  • Connection Creation Parameters
  • Creating Connections

Was this helpful?

Export as PDF
  1. Gretel Basics
  2. Getting Started
  3. Gretel Connectors
  4. Database

MySQL

Connect to your MySQL databases.

Getting Started

Prerequisites to create a MySQL based workflow. You will need

  1. A source MySQL connection.

  2. (optional) A list of tables OR SQL queries.

  3. (optional) A destination MySQL connection.

For the source database connection, we recommend using a backup or clone with read-only permissions, instead of connecting directly to your production database.

Do not use your input database connection as an output connector. This action can result in the unintended overwriting of existing data.

Create a Connection

A mysql connection is created using the following parameters:

Connection Creation Parameters

name

Display name of your choosing used to identify your connection within Gretel.

my-mysql-connection

username

Unique identifier associated with specific account authorized to access database.

john

password

Security credential to authenticate username.

...

host

Fully qualified domain name (FQDN) used to establish connection to database server.

myserver.example.com

port

Port number; If left empty, the default value - 3306- will be used.

3306

database

Name of database to connect to.

mydatabase

(optional) params

Optional JDBC URL parameters that can be used for advanced configuration.

TrustServerCertificate=True&useSSL=false

Creating Connections

First, create a file on your local computer containing the connection credentials. This file should also include type, name , config, and credentials. The config and credentials fields should contain fields that are specific to the connection being created.

Below is an example MySQL connection:

{
    "type": "mysql",
    "name": "my-mysql-connection",
    "config": {
        "username": "john",
        "host": "myserver.example.com",
        "port": 3306,
        "database": "mydatabase",
        "params": "TrustServerCertificate=True&useSSL=false"
    },
    "credentials": {
        "password": "..."
    }
}

Now that you've created the credentials file, use the CLI to create the connection

gretel connections create --project [project id] --from-file [credential_file.json]
  • Click the New Connection button.

  • Step 1, choose the Type for the Connection - MySQL.

  • Step 2, choose the Project for your Connection.

  • Step 3, fill in the credentials and select Add Connection.

from gretel_client import create_or_get_unique_project
from gretel_client.config import get_session_config
from gretel_client.rest_v1.api.connections_api import ConnectionsApi
from gretel_client.rest_v1.models import (
    CreateConnectionRequest,
    UpdateConnectionRequest,
)

session = get_session_config()
connection_api = session.get_v1_api(ConnectionsApi)

project = create_or_get_unique_project(name="mysql-workflow")

connection = connection_api.create_connection(
    CreateConnectionRequest(
        name="my-mysql-connection",
        project_id=project.project_guid,
        type="mysql",
        config={
            "username": "john",
            "host": "myserver.example.com",
            "database": "mydatabase",
            #"port": 3306,
            #"params": "TrustServerCertificate=True&useSSL=false",
        },
        # note: best practice is to read in credentials from a file
        # or secret instead of directly embedding sensitive values
        # in python code.
        credentials={
            "password": "...",
        },
    )
)
PreviousDatabaseNextPostgreSQL

Last updated 29 days ago

Was this helpful?

Navigate to the using the menu item in the left sidebar.

Connections page
Step 1, choose the Type of connection
Step 3, fill in credentials