Tuesday, 21 April 2026

n8n MySQL Tutorial: How to Automate Database Workflows

n8n + MySQL Tutorial

How to Use n8n with MySQL for Database Automation

Learn how to connect n8n to MySQL, run queries, insert records, update rows, and automate database workflows.

If you want to automate your database tasks, combining n8n with MySQL is a great setup. MySQL stores your data, while n8n helps automate what happens before and after every database action.

💡 Example: when a form is submitted, n8n can save the lead to MySQL, send a Telegram alert, and update Google Sheets automatically.

What You’ll Learn

  • How to connect MySQL to n8n
  • How to run SELECT queries
  • How to INSERT new rows
  • How to UPDATE records
  • How to DELETE data safely
  • How to use MySQL in real workflows

Why Use n8n with MySQL?

MySQL is one of the most common relational databases for web apps, CRMs, dashboards, and internal systems. n8n helps you automate how data enters, changes, and moves across your systems.

  • Save form submissions to a database
  • Read customer or order data automatically
  • Update records after payment or approval
  • Delete old records on schedule
  • Sync MySQL data with email, Telegram, CRMs, and APIs

Step 1: Prepare Your MySQL Database

Before connecting n8n, make sure your MySQL server is running and you have:

  • Host
  • Port
  • Database name
  • Username
  • Password

It is best to create a dedicated database user for n8n instead of using your main admin account.

⚠️ Security tip: give the n8n database user only the permissions it actually needs.

Step 2: Add MySQL Credentials in n8n

In n8n, create a new MySQL credential and enter your connection details.

  1. Open Credentials in n8n
  2. Create a new MySQL credential
  3. Enter host, port, database, username, and password
  4. Save and test the connection

Once connected, you can use MySQL inside your workflows to query and modify database records.

Step 3: Read Data with SELECT

The most common database action is reading data. In MySQL, this is done with the SELECT statement.

SELECT id, full_name, email
FROM customers
ORDER BY id DESC;

In n8n, you can use a MySQL node or a query-based setup to run this and return rows for the next node in your workflow.

Step 4: Insert New Rows

To save new data, use INSERT.

INSERT INTO customers (full_name, email, phone)
VALUES ('John Doe', 'john@example.com', '09171234567');

This is useful for leads, registrations, orders, contact form entries, and chatbot submissions.

Step 5: Update Existing Records

Use UPDATE when you need to change existing rows.

UPDATE customers
SET phone = '09998887777'
WHERE id = 1;

This is useful for updating order status, customer details, payment state, or workflow progress.

Step 6: Delete Records Carefully

Use DELETE only when needed, and always include a clear WHERE condition to avoid removing everything by mistake.

DELETE FROM customers
WHERE id = 1;
Warning: running DELETE without a WHERE clause can remove all rows from a table.

Step 7: Use Dynamic Data from Previous Nodes

One of the best parts of n8n is that you can use values from previous nodes inside your database logic.

Example expression:

{{ $json.email }}

n8n also supports referencing data from earlier nodes when building more advanced workflows.

Example n8n + MySQL Workflow

Webhook
   ↓
Set
   ↓
MySQL (INSERT lead)
   ↓
MySQL (SELECT latest data)
   ↓
Telegram
   ↓
Gmail

In this workflow:

  • A webhook receives a form submission
  • A Set node formats the incoming data
  • MySQL inserts the record
  • Another MySQL step reads the saved row
  • Telegram and Gmail notify your team

Real Use Cases

Lead capture systems
Order and payment tracking
Attendance and RFID systems
CRM and admin dashboards

Best Practices

  • Use a separate MySQL user for n8n
  • Back up your database before testing destructive queries
  • Test SELECT first before running UPDATE or DELETE
  • Log important outputs during development
  • Keep table and column names clear and consistent

Common Errors and Fixes

1. Connection failed
Check host, port, username, password, and whether the MySQL server accepts remote connections.

2. Access denied
The database user may not have the right privileges.

3. Query returned nothing
Review your table name, WHERE clause, and incoming data.

4. Wrong data inserted
Check your n8n expressions and field mappings carefully.

5. Update or delete affected too many rows
Always verify your WHERE condition before executing the query.

Watch My Automation Videos on YouTube

I share n8n workflows, automation tutorials, and AI system ideas on my YouTube channel.

▶ Visit My YouTube Channel

FAQ

Can I use n8n to insert data into MySQL automatically?
Yes. n8n can receive data from forms, APIs, spreadsheets, or webhooks and save it into MySQL automatically.

Can I update MySQL rows from n8n?
Yes. You can use update queries to change values such as status, amount, timestamps, or user details.

Can I use MySQL with Telegram, Gmail, or Google Sheets in the same workflow?
Yes. That is one of the biggest strengths of n8n.


SEO Title

n8n MySQL Tutorial: How to Automate Database Workflows

Meta Description

Learn how to use n8n with MySQL to automate database queries, inserts, updates, deletes, and connected workflow actions.

No comments:

Post a Comment

n8n + Microsoft Outlook Tutorial

n8n + Microsoft Outlook Tutorial How to Use n8n with Microsoft Outlook for Email Automation ...