How to Connect n8n to MySQL: Query and Sync Databases Without Code (2025)
MySQL powers a huge share of the world's applications, and connecting it to n8n turns your database into an automation hub — sync records to a CRM, trigger emails on new rows, or build reports on a schedule. This guide walks you through the setup step by step.
Step 1: Add MySQL credentials in n8n
In n8n, go to Credentials → New → MySQL. You'll need:
- Host — your database server IP or hostname
- Database — the schema name
- User and Password
- Port — 3306 by default
- SSL — enable for managed databases like PlanetScale, AWS RDS, or DigitalOcean
Click Test to confirm the connection before saving.
Step 2: Run your first query
Add a MySQL node and choose an operation. The most common are:
- Execute Query — run raw SQL, e.g.
SELECT * FROM orders WHERE status = 'pending' - Insert — map incoming fields to columns without writing SQL
- Update — modify rows matching a key
Use n8n expressions to inject dynamic values — for example WHERE created_at > '{{ $json.since }}' — so the query adapts to each execution.
🚀 Skip the build — get the ready-made template
This article shows you how it works. The Text-to-SQL Agent template gives you the finished n8n workflow — import it, add your credentials, and go live today.
Get Text-to-SQL Agent on Gumroad →
Step 3: Sync on a schedule
Pair the MySQL node with a Schedule Trigger to poll for new or changed rows every few minutes and push them to Slack, Google Sheets, or your CRM. Track the last-seen ID or timestamp in a static data field so you never process the same row twice.
Common errors and fixes
- ECONNREFUSED — the host or port is wrong, or your DB isn't accepting remote connections. Whitelist your n8n server's IP.
- Access denied — the MySQL user lacks privileges or host-based grants. Grant access from n8n's IP.
- SSL required — managed providers force TLS; toggle SSL on in the credential.
- Timeouts on big tables — add
LIMITand paginate instead of pulling everything at once.
Go further: ask your database in plain English
Once n8n can talk to MySQL, the next step is letting your team query it without knowing SQL. An AI Text-to-SQL agent takes a plain-English question, generates the query, runs it against your database, and returns a clean answer — perfect for a Slack "/ask" command over your data.
Ready to automate?
Don't rebuild this from scratch. The Text-to-SQL Agent template is a complete, importable n8n workflow — configure your credentials and it runs in minutes.