Loading Data from MySQL
to Azure Synapse
using dlt
in Python
Join our Slack community or book a call with our support engineer Violetta.
MySQL
is a widely used relational database management system (RDBMS). It is free and open-source, making it ideal for both small and large applications. Azure Synapse
Analytics is a limitless analytics service that brings together enterprise data warehousing and Big Data analytics. This documentation explains how to load data from MySQL
to Azure Synapse
using the open-source Python library dlt
. For more information about MySQL
, visit here.
dlt
Key Features
- Install dlt with Synapse: To install the DLT library with Synapse dependencies, use
pip install dlt[synapse]
. Learn more. - Supported column hints: Synapse supports
primary_key
andunique
column hints. Learn more. - Staging support: Synapse supports Azure Blob Storage as a file staging destination. Learn more.
- Setup guide: Follow the step-by-step guide to set up Azure Synapse as your destination. Learn more.
- Table index type: Configure the table index type of the created tables with the
synapse_adapter
. Learn more.
Getting started with your pipeline locally
0. Prerequisites
dlt
requires Python 3.8 or higher. Additionally, you need to have the pip
package manager installed, and we recommend using a virtual environment to manage your dependencies. You can learn more about preparing your computer for dlt in our installation reference.
1. Install dlt
First you need to install the dlt
library with the correct extras for Azure Synapse
:
pip install "dlt[synapse]"
The dlt
cli has a useful command to get you started with any combination of source and destination. For this example, we want to load data from MySQL
to Azure Synapse
. You can run the following commands to create a starting point for loading data from MySQL
to Azure Synapse
:
# create a new directory
mkdir sql_database_mysql_pipeline
cd sql_database_mysql_pipeline
# initialize a new pipeline with your source and destination
dlt init sql_database synapse
# install the required dependencies
pip install -r requirements.txt
The last command will install the required dependencies for your pipeline. The dependencies are listed in the requirements.txt
:
sqlalchemy>=1.4
dlt[synapse]>=0.4.7
You now have the following folder structure in your project:
sql_database_mysql_pipeline/
├── .dlt/
│ ├── config.toml # configs for your pipeline
│ └── secrets.toml # secrets for your pipeline
├── sql_database/ # folder with source specific files
│ └── ...
├── sql_database_pipeline.py # your main pipeline script
├── requirements.txt # dependencies for your pipeline
└── .gitignore # ignore files for git (not required)
2. Configuring your source and destination credentials
The dlt
cli will have created a .dlt
directory in your project folder. This directory contains a config.toml
file and a secrets.toml
file that you can use to configure your pipeline. The automatically created version of these files look like this:
generated config.toml
# put your configuration values here
[runtime]
log_level="WARNING" # the system log level of dlt
# use the dlthub_telemetry setting to enable/disable anonymous usage data reporting, see https://dlthub.com/docs/telemetry
dlthub_telemetry = true