Download icon
Query icon

Create a table and load CSV data into MySQL with SQL

Extract a remote CSV and bulk-load it into MySQL using Kestra. Declarative SQL tasks, secret-managed credentials, and pluginDefaults remove boilerplate.

Categories
Data

Move a remote CSV file into a MySQL table without writing glue code or babysitting cron jobs. This blueprint downloads a dataset over HTTP, creates the destination table if it does not exist, and bulk-loads the rows with MySQL LOAD DATA LOCAL INFILE, all as declarative YAML. It solves the common ELT problem of getting external flat files into a relational database reliably, with credentials kept out of the flow through Kestra secrets.

How it works

  1. extract uses io.kestra.plugin.core.http.Download to fetch the orders.csv dataset from a remote URL and stage it in Kestra internal storage.
  2. enable_local_files runs io.kestra.plugin.jdbc.mysql.Query to SET GLOBAL local_infile=1, allowing MySQL to accept client-side file loads.
  3. create_table runs another io.kestra.plugin.jdbc.mysql.Query to create the target table (named from the table variable) with columns for order, customer, product, price, quantity, and total.
  4. load_data passes the downloaded file via inputFile and runs LOAD DATA LOCAL INFILE to bulk-insert the CSV rows, skipping the header with IGNORE 1 ROWS.

Connection settings (url, username, password) are defined once in pluginDefaults for io.kestra.plugin.jdbc.mysql.Query, so every query task inherits them.

What you get

  • A repeatable extract-and-load pipeline from a remote CSV to MySQL.
  • Idempotent table creation with create table if not exists.
  • High-throughput bulk loading via LOAD DATA LOCAL INFILE.
  • Credentials referenced as a secret, never hardcoded.
  • Shared connection config through pluginDefaults to eliminate repetition.

Who it's for

  • Data engineers building ingestion pipelines into MySQL.
  • Analytics teams loading flat-file extracts into a staging schema.
  • Developers wanting a clean, declarative starting point for ELT into MySQL.

Why orchestrate this with Kestra

MySQL has no native scheduler for multi-step data workflows. Kestra fills that gap: trigger the load on a schedule or on an event, retry failed steps automatically, capture full execution lineage and logs, and keep everything as version-controlled YAML. Connection details live in pluginDefaults and secrets, so the same flow runs across environments without edits.

Prerequisites

  • A reachable MySQL instance (the defaults target jdbc:mysql://host.docker.internal:3306/stage).
  • MySQL configured to permit LOAD DATA LOCAL INFILE.
  • Network access to the remote CSV URL.

Secrets

  • DB_PASSWORD: the MySQL password used in the pluginDefaults connection.

Quick start

  1. Start a local MySQL instance, for example: docker run -d -p 3306:3306 --name mymysql -v mymysqldb:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=topSecret42 -e MYSQL_DATABASE=stage mysql:latest
  2. Add the DB_PASSWORD secret in Kestra.
  3. Adjust the url, username, and table values to match your environment.
  4. Execute the flow and confirm the rows land in the target table.

How to extend

  • Swap the extract URL to ingest your own CSV source.
  • Adjust the create_table schema to match your dataset.
  • Add a Schedule trigger to run loads on a cadence, or an event trigger to load on file arrival.
  • Append validation or transformation queries after load_data, or fan out to multiple tables.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.