step

mysql

Execute MySQL database operations for queries, inserts, updates, and deletes.

Overview

Execute MySQL database operations for queries, inserts, updates, and deletes.

Supports operations: - query: Execute SELECT queries and return results - execute: Execute any SQL statement (INSERT, UPDATE, DELETE, DDL, etc.) - insert: Insert one or multiple rows into a table - update: Update rows matching a condition - delete: Delete rows matching a condition

Setup: 1. Install MySQL Server (https://dev.mysql.com/downloads/mysql/) - Or use a cloud provider: AWS RDS, Google Cloud SQL, Azure Database - Or use a managed service: PlanetScale, DigitalOcean, etc. 2. Create a database and user with appropriate permissions 3. Get your connection details (host, port, username, password, database) 4. Store credentials securely (e.g., environment variables)

Connection String Format: mysql://username:password@host:port/database

Required Permissions: - SELECT: for query operations - INSERT: for insert operations - UPDATE: for update operations - DELETE: for delete operations - For execute operation: depends on the SQL being executed

Security: - Always use parameterized queries with params to prevent SQL injection - Never concatenate user input directly into SQL queries - Use read-only users for query-only workflows - Store passwords in environment variables, never in code - Use SSL/TLS for production connections - Implement connection pooling for high-traffic applications

Examples

Query with parameters

Select users with parameterized query to prevent SQL injection

type: mysql
connection_string: ${env:MYSQL_URL}
operation: query
query: "SELECT id, email, name, age FROM users WHERE age > %(min_age)s AND status = %(status)s ORDER BY created_at DESC"
params:
  min_age: 18
  status: active
output_to: users

Insert single record

Insert a new user into the database

type: mysql
connection_string: ${env:MYSQL_URL}
operation: insert
table: users
data:
  email: ${user.email}
  name: ${user.name}
  age: 25
  created_at: ${meta.timestamp}
output_to: new_user

Insert multiple records

Bulk insert multiple rows in one operation

type: mysql
connection_string: ${env:MYSQL_URL}
operation: insert
table: events
data:
  - event_type: page_view
    user_id: ${user.id}
    page: /home
    timestamp: ${meta.timestamp}
  - event_type: button_click
    user_id: ${user.id}
    element: signup_btn
    timestamp: ${meta.timestamp}
output_to: inserted_events

Update records

Update user status with a WHERE clause

type: mysql
connection_string: ${env:MYSQL_URL}
operation: update
table: users
set:
  status: verified
  verified_at: ${meta.timestamp}
where: "email = %(email)s"
params:
  email: ${user.email}
output_to: update_result

Delete old records

Delete records older than a certain date

type: mysql
connection_string: ${env:MYSQL_URL}
operation: delete
table: temp_logs
where: "created_at < DATE_SUB(NOW(), INTERVAL 7 DAY)"
output_to: delete_result

Execute raw SQL

Execute any SQL statement (CREATE TABLE, ALTER, etc.)

type: mysql
connection_string: ${env:MYSQL_URL}
operation: execute
query: |
  INSERT INTO audit_log (action, user_id, ip_address, timestamp)
  VALUES (%(action)s, %(user_id)s, %(ip)s, NOW())
params:
  action: user_login
  user_id: ${user.id}
  ip: ${request.ip}
output_to: audit_result

Query with JOIN

Complex query with joins and aggregation

type: mysql
connection_string: ${env:MYSQL_URL}
operation: query
query: |
  SELECT
    o.id,
    o.total,
    o.status,
    c.email,
    c.name,
    COUNT(oi.id) as item_count
  FROM orders o
  JOIN customers c ON o.customer_id = c.id
  LEFT JOIN order_items oi ON o.id = oi.order_id
  WHERE o.status = %(status)s
  GROUP BY o.id, o.total, o.status, c.email, c.name
  ORDER BY o.created_at DESC
  LIMIT 100
params:
  status: pending
output_to: pending_orders

Fetch single row

Get one user by email

type: mysql
connection_string: ${env:MYSQL_URL}
operation: query
query: "SELECT id, email, name, age FROM users WHERE email = %(email)s"
params:
  email: ${user.email}
fetch_one: true
output_to: user_profile

Connection with individual params

Connect using separate host, user, password instead of connection string

type: mysql
host: mysql.example.com
port: 3306
user: ${env:MYSQL_USER}
password: ${env:MYSQL_PASSWORD}
database: production
operation: query
query: "SELECT COUNT(*) as user_count FROM users"
output_to: stats

Configuration

Parameter Type Required Description
connection_string string No MySQL connection string (format: mysql://username:password@host:port/database or mysql+pymysql://...). Takes precedence over individual connection parameters
host string No MySQL server hostname or IP address (alternative to connection_string)
port integer No MySQL server port number
Default: 3306
user string No MySQL username for authentication
password string No MySQL password for authentication
database string No MySQL database/schema name to connect to
operation string Yes Operation to perform: query (SELECT), execute (any SQL), insert (add rows), update (modify rows), delete (remove rows)
Options: query, execute, insert, update, delete
query string No SQL query to execute (required for query and execute operations). Use %(param)s for parameter substitution
table string No Table name for insert, update, or delete operations
data string No Data to insert or update. Single dict for one row, list of dicts for multiple rows
set string No Fields to update (for update operation, alternative to data)
where string No WHERE clause for update or delete operations (without the WHERE keyword). Use %(param)s for parameters
params string No Parameters for parameterized queries (prevents SQL injection)
fetch_one boolean No For query operations, return only the first row instead of all rows
Default: false
return_id boolean No For insert operations, return the last inserted row ID
Default: true
charset string No Character set for the connection (utf8mb4 recommended for full Unicode support including emojis)
Default: "utf8mb4"
autocommit boolean No Enable autocommit mode (each statement is committed immediately)
Default: true
timeout integer No Connection and query timeout in seconds
Default: 30
output_to string No Key name where query results or operation status will be stored in the event
Default: "mysql"

Base Configuration

These configuration options are available on all steps:

Parameter Type Default Description
name null Optional name for this step (for documentation and debugging)
description null Optional description of what this step does
retries integer 0 Number of retry attempts (0-10)
backoff_seconds number 0 Backoff (seconds) applied between retry attempts
retry_propagate boolean false If True, raise last exception after exhausting retries; otherwise swallow.