Learn how to connect n8n to MySQL with simple steps, best practices, and tips to ensure a smooth, secure workflow integration.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
The direct answer is: you connect n8n to MySQL by creating a MySQL credential inside n8n and then using the built‑in MySQL node in your workflow. You point the credential to your database host, port, username, password, and database name. After that, you can run real SQL queries (SELECT, INSERT, UPDATE, DELETE) directly from n8n nodes.
n8n talks to MySQL using its built‑in MySQL node. n8n does not magically “scan your database”; you explicitly run SQL queries. A credential is simply stored connection info (host, username, etc.) so nodes can connect without exposing passwords in your workflow JSON.
If the test fails, it’s usually networking: Docker networks, firewalls, or MySQL not allowing external connections. n8n needs permission to access the DB — this is not automatic.
In any workflow:
SELECT * FROM users WHERE email = {{$json.email}}; // Using incoming workflow data
n8n will return rows as JSON. Each row becomes an item, which you can send to the next node (Slack, HTTP Request, another DB, etc.).
INSERT INTO orders (user_id, total_price, created_at)
VALUES ({{$json.userId}}, {{$json.total}}, NOW());
Expressions (like {{$json.userId}}) pull values from previous nodes. This is how you pass API data into SQL safely.
The most common connection mistake: using localhost. Inside Docker, localhost means "inside the same container", not your machine. If MySQL is another container, use its container name:
If MySQL is running on the host machine, you usually connect to host.docker.internal (Mac/Windows) or the host IP for Linux.
To connect n8n to MySQL, you create a MySQL credential with host/user/password/database, test it, and then use the MySQL node to run SQL. From there, you can read or write data as part of any workflow, using expressions to feed real-time values into your queries. This setup is stable for production as long as networking, permissions, and timeouts are correctly configured.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.