Back to Blog
n8nMySQLdatabaseintegrationautomation

n8n + MySQL Integration: 5 Powerful Workflows You Can Build

n8nautomation TeamApril 13, 2026
TL;DR: The n8n MySQL integration lets you automate database operations without writing backend code. With 6 built-in actions (Select, Insert, Update, Delete, Upsert, Execute SQL), you can build workflows that save form submissions, sync inventory, archive messages, clean old records, and even power AI chatbots that query your database in natural language.

MySQL remains one of the most widely used relational databases in 2026, powering everything from e-commerce platforms to CRM systems. The n8n MySQL integration gives you programmatic access to your database through visual workflows, eliminating the need for custom backend scripts every time you want to automate a database operation.

Whether you're saving form submissions, syncing inventory between systems, or building an AI assistant that queries your database, n8n's MySQL node handles the connection, query execution, and error handling automatically.

Why Automate MySQL with n8n

Traditional MySQL automation requires writing backend scripts, managing database connections, handling errors, and deploying code to a server. With n8n, you skip all of that. The MySQL node provides a visual interface for database operations with built-in connection pooling, error handling, and retry logic.

The MySQL node supports six core actions: Select (query records), Insert (add new records), Update (modify existing records), Delete (remove records), Insert or Update (upsert operations), and Execute SQL (run custom queries). These cover 95% of database automation needs without touching SQL directly, though you can always drop into raw SQL when needed.

Unlike cloud automation tools that charge per execution, self-hosted n8n instances run unlimited MySQL workflows at no extra cost. Managed hosting providers like n8nautomation.cloud offer dedicated instances starting at $15/month with automatic backups and 24/7 uptime, giving you production-grade reliability without the maintenance overhead.

Setting Up the MySQL Node in n8n

Before building workflows, you need to connect n8n to your MySQL database. Add the MySQL node to any workflow and click Create New Credential. You'll need five pieces of information:

  • Host: Your MySQL server address (IP or domain)
  • Port: Usually 3306 (default MySQL port)
  • Database: The specific database name you want to access
  • User: A MySQL user with appropriate permissions
  • Password: The user's password
Note: Create a dedicated MySQL user for n8n with only the permissions it needs (SELECT, INSERT, UPDATE, DELETE). Avoid using root credentials. If your MySQL server is behind a firewall, you'll need to whitelist your n8n instance IP address.

Once connected, test the credential by running a simple SELECT query. If the connection fails, check that your MySQL server allows remote connections (bind-address in my.cnf should be 0.0.0.0, not 127.0.0.1) and that your firewall rules permit traffic on port 3306.

5 Powerful MySQL Workflows You Can Build

1. Auto-Save Form Submissions to Database

Every time someone submits a contact form, survey, or signup page, capture that data in MySQL automatically. This workflow eliminates manual data entry and ensures you never lose a lead.

Workflow structure:

  • Webhook node: Receive form POST data from your website
  • Set node: Map form fields to database columns
  • MySQL node (Insert): Add the record to your contacts table
  • Slack node: Send a notification when a high-value lead submits

In the MySQL node, select Insert as the operation, choose your target table, and map incoming fields to columns. Use the expression editor to transform data if needed (trim whitespace, format phone numbers, convert timestamps).

2. Sync Inventory Levels Between Shopify and MySQL

If you run an e-commerce store on Shopify but track inventory in a custom MySQL database, keep them synchronized in real-time. Every time a product sells, update your central inventory system automatically.

Workflow structure:

  • Shopify Trigger node: Listen for order/created events
  • Loop Over Items node: Process each product in the order
  • MySQL node (Update): Decrease inventory count by quantity sold
  • IF node: Check if inventory falls below reorder threshold
  • Gmail node: Send restock alert if inventory is low

In the MySQL Update node, use an expression like {{$json.quantity - $node["Shopify Trigger"].json["line_items"][0]["quantity"]}} to decrement the stock count. Add error handling to prevent negative inventory values.

3. Archive Slack Messages to Searchable Database

Slack's free plan only keeps 90 days of message history. Archive every message to MySQL for unlimited searchable history. This is especially valuable for compliance, customer support records, or product feedback tracking.

Workflow structure:

  • Slack Trigger node: Listen for new messages in specific channels
  • Set node: Extract user ID, channel, timestamp, and message text
  • MySQL node (Insert): Save to messages table
  • MySQL node (Insert): If the message has attachments, save to separate attachments table

Create a messages table with columns for id, user_id, channel, text, timestamp, and thread_ts. Use full-text indexing on the text column for fast searches. Later, you can build a simple search interface that queries this archive.

Tip: Use the MySQL Execute SQL action to create full-text indexes: ALTER TABLE messages ADD FULLTEXT(text). Then query with SELECT * FROM messages WHERE MATCH(text) AGAINST('search term') for blazing-fast searches across millions of messages.

4. Scheduled Data Cleanup and Archival

Keep your MySQL database fast by automatically archiving old records and deleting expired data. Run this workflow nightly to move completed orders older than 6 months to an archive table and delete soft-deleted records older than 90 days.

Workflow structure:

  • Schedule Trigger node: Run daily at 2 AM (cron: 0 2 * * *)
  • MySQL node (Execute SQL): INSERT INTO orders_archive SELECT * FROM orders WHERE completed_at < DATE_SUB(NOW(), INTERVAL 6 MONTH)
  • MySQL node (Delete): Remove those records from the main orders table
  • MySQL node (Execute SQL): DELETE FROM users WHERE deleted_at < DATE_SUB(NOW(), INTERVAL 90 DAY)
  • MySQL node (Execute SQL): OPTIMIZE TABLE orders to reclaim disk space

Wrap the entire workflow in error handling. If any step fails, send an alert to your operations team via Slack or email. Use transactions when moving data between tables to prevent data loss if the workflow crashes mid-execution.

5. AI-Powered Chatbot with Natural Language Database Queries

Build a chatbot that lets non-technical team members query your MySQL database using plain English. Ask "How many orders did we get last week?" and get an instant answer pulled from your live database.

Workflow structure:

  • Webhook node: Receive chat messages from your frontend
  • OpenAI node (GPT-4): Convert natural language to SQL query
  • Code node: Validate and sanitize the generated SQL
  • MySQL node (Execute SQL): Run the query
  • OpenAI node: Convert results into a natural language response
  • Respond to Webhook node: Return the answer

In the first OpenAI node, provide a system prompt with your database schema: "You are a SQL expert. Convert questions to MySQL queries. Tables: orders (id, customer_id, total, created_at), customers (id, name, email). Only generate SELECT queries." This prevents the AI from generating UPDATE or DELETE queries that could modify data.

In the Code node, add a whitelist check: reject any query containing UPDATE, DELETE, DROP, ALTER, INSERT, or TRUNCATE. Only allow SELECT queries. Add a LIMIT clause if one isn't present to prevent massive result sets.

Best Practices for MySQL Automation

Always use parameterized queries when inserting user input to prevent SQL injection. The MySQL node handles this automatically when you use the Insert/Update actions, but if you're using Execute SQL with user data, use the n8n expression system to escape values properly.

Set appropriate timeout values for long-running queries. In n8n's MySQL node settings, you can configure connection timeout and query timeout. For analytics queries that might take 30+ seconds, increase the timeout. For transactional workflows, keep it under 5 seconds and optimize slow queries.

Use connection pooling for high-volume workflows. When running on n8nautomation.cloud or self-hosted instances, configure the maximum connection pool size in your MySQL credential settings. Start with 5 connections and increase if you see connection timeout errors.

Implement retry logic for transient failures. MySQL connections can fail due to network hiccups, server restarts, or connection pool exhaustion. Use n8n's built-in retry settings (under workflow settings) to automatically retry failed executions up to 3 times with exponential backoff.

Common Use Cases Across Industries

E-commerce: Sync product catalogs between your website and MySQL, track inventory in real-time, log customer support tickets, archive order history, and generate daily sales reports by querying transaction data.

SaaS platforms: Log user activity for analytics, track feature usage by querying event tables, sync user profiles between authentication systems and MySQL, manage subscription billing by triggering workflows when payments succeed or fail.

Marketing teams: Save campaign performance data from Google Analytics, track email engagement by logging opens and clicks, build custom dashboards by pulling data from MySQL into Google Sheets, segment audiences based on database queries.

Development teams: Automate database migrations by running scheduled SQL scripts, sync test data from production to staging (with PII masking), log application errors to MySQL for debugging, trigger alerts when database size exceeds thresholds.

The n8n MySQL integration eliminates the gap between your database and the rest of your automation stack. Instead of writing custom scripts for every database operation, you build visual workflows that are easier to maintain, easier to debug, and easier to hand off to teammates who don't write code.

Ready to automate with n8n?

Get affordable managed n8n hosting with 24/7 support.