n8n MySQL Node Connection Timeout Error

Step by Step Guide to solve n8n MySQL node connection timeout


 

Who this is for: Developers and DevOps engineers running n8n workflows that need reliable MySQL connectivity in Docker, Kubernetes, or self‑hosted environments. We cover this in detail in the n8n Node Specific Errors Guide.


Quick Diagnosis: Fix the timeout in 5 minutes

  1. Verify you can reach MySQL from the n8n host (nc -z <host> 3306).
  2. In the MySQL node, set Connect Timeout → 30000 ms (or higher).
  3. Increase MySQL server variables wait_timeout and interactive_timeout to ≥ 300 seconds.
  4. If using SSL, add the correct ca.pem/cert.pem files and enable TLS 1.2.
  5. Restart the workflow – the node should now connect without timing out.

1. What the “Connection timeout” error really means

If you encounter any n8n smtp node send failure resolve them before continuing with the setup.

Symptom Typical n8n log line
Error: MySQL node connection timeout after 10000 ms 2024-09-01 12:34:56 – error – MySQL node connection timeout after 10000 ms
Error: ECONNREFUSED … – error – connect ECONNREFUSED 10.0.2.5:3306
Error: ER_ACCESS_DENIED_ERROR … – error – ER_ACCESS_DENIED_ERROR: Access denied for user
Underlying cause
  • n8n could not establish a TCP socket within the configured timeout.
  • The server rejected the connection (firewall, bind address, wrong port).
  • Authentication succeeded but the server closed the socket after the handshake (often a wait_timeout issue).

EEFA note: In production, a timeout often masks a deeper network policy (e.g., security groups, VPC peering) that silently drops packets after a few seconds. Always confirm connectivity before tweaking n8n settings.


2. Common root‑causes for MySQL node timeouts in n8n

If you encounter any n8n excel node file corruption resolve them before continuing with the setup.

Category Typical trigger
Network path VPC firewall, Docker bridge, VPN split‑tunnel
MySQL server config wait_timeout < connect_timeout
n8n node config Default Connect Timeout = 10 000 ms (insufficient for high latency)
TLS/SSL mismatch Missing CA bundle or outdated TLS version
Connection pooling Reusing stale sockets after a server restart
Quick verification
  • nc -zvw5 <mysql-host> 3306 from the n8n container
  • SHOW VARIABLES LIKE 'wait_timeout';
  • Check node UI → *Advanced* → *Connect Timeout*
  • Look for TLS handshake timeout in n8n logs
  • Enable *Force New Connection* in node options

3. Step‑by‑step: Verify raw connectivity

*Confirm the network and MySQL handshake work before changing any n8n settings.*

We cover this in detail in the n8n Node Specific Errors Guide

# Test TCP reachability
nc -zvw5 mysql.example.com 3306

Expected output:

Connection to mysql.example.com 3306 port [tcp/mysql] succeeded!
# Test MySQL handshake without authentication
mysql -h mysql.example.com -P 3306 -u dummy -pdummy --connect-timeout=5 -e "SELECT 1;"

You should see 1 or a clear authentication error—not a timeout. If either command fails, fix firewalls, VPC routes, or DNS first.


4. Configure the MySQL node for longer timeouts

If you encounter any n8n wait node timeout resolve them before continuing.

Purpose: Extend the socket‑creation window so high‑latency or busy networks can complete the handshake.

4.1 Set the timeout in the node UI

  1. Open the workflow → edit the MySQL node.
  2. Click Advanced Settings → enable Custom Timeout.
  3. Set Connect Timeout (ms) to a value that exceeds your worst‑case latency (e.g., 30000).
  4. (Optional) Enable Force New Connection to avoid re‑using stale sockets.

4.2 JSON representation (for reference)

{
  "host": "mysql.example.com",
  "port": 3306,
  "user": "n8n_user",
  "password": "••••••"
}
{
  "connectTimeout": 30000,
  "forceNewConnection": true
}

EEFA tip: Avoid setting the timeout arbitrarily high (> 2 min) in production; it masks genuine network failures and can tie up worker threads.


5. Tune MySQL server variables

Purpose: Ensure the server does not close idle connections before n8n finishes its handshake.

5.1 Inspect current values

SHOW VARIABLES LIKE 'wait_timeout';
SHOW VARIABLES LIKE 'interactive_timeout';
SHOW VARIABLES LIKE 'connect_timeout';

5.2 Raise them to safe defaults (e.g., 300 seconds)

SET GLOBAL wait_timeout = 300;
SET GLOBAL interactive_timeout = 300;
SET GLOBAL connect_timeout = 10;

5.3 Persist the changes in my.cnf

[mysqld]
wait_timeout = 300
interactive_timeout = 300
connect_timeout = 10

Restart MySQL to apply:

systemctl restart mysqld   # or `service mysql restart`

EEFA warning: Raising wait_timeout too much can keep idle connections open, consuming resources. Monitor SHOW PROCESSLIST; after the change.


6. SSL/TLS considerations (if your MySQL endpoint requires encryption)

Setting in n8n node Required file Common pitfalls
Use TLS ca.pem (CA bundle) Wrong CA → handshake fails → timeout
Client Cert client-cert.pem Expired cert → connection reset
Client Key client-key.pem Permissions too restrictive (600) → node can’t read

6.1 JSON snippet for TLS configuration

{
  "ssl": {
    "ca": "/secrets/mysql/ca.pem",
    "cert": "/secrets/mysql/client-cert.pem",
    "key": "/secrets/mysql/client-key.pem"
  }
}
{
  "ssl": {
    "rejectUnauthorized": true
  }
}

6.2 Verify the TLS handshake manually

openssl s_client -connect mysql.example.com:3306 -CAfile /secrets/mysql/ca.pem

If the handshake stalls, the timeout will reappear – fix the certificate chain first.


7. Debugging with n8n logs

Enable debug logging in ~/.n8n/config:

[logging]
level = "debug"

Watch the logs while the workflow runs:

docker logs -f n8n_container
# Look for lines containing “MySQL node” and “timeout”

Typical useful output:

2024-09-01 12:34:56 - debug - MySQL node: establishing TCP connection to mysql.example.com:3306
2024-09-01 12:34:56 - error - MySQL node connection timeout after 30000 ms

If you see “TLS handshake timeout”, revisit the SSL/TLS step.


8. Checklist – Resolve MySQL node timeout

  • Network reachablenc succeeds from n8n host.
  • MySQL node timeout set ≥ 30 000 ms (or appropriate for latency).
  • Server variables wait_timeout & interactive_timeout ≥ 300 s.
  • SSL files present, correct permissions, and match server config.
  • Force New Connection enabled if using connection pooling.
  • n8n logs show successful “connected” message, not “timeout”.

9. Frequently asked questions

Question Answer
Why does increasing the node timeout not help? The TCP packets never reach the MySQL host (firewall/VPC). Fix network first.
Can I set the timeout per workflow instead of per node? No. n8n’s MySQL node only respects the **Connect Timeout** field; workflow‑level timeouts affect the whole execution, not socket creation.
Is there a way to auto‑retry on timeout? Wrap the MySQL node in an **IF** block with a **Retry** node (set retries = 3, delay = 5 s).
My server uses max_allowed_packet=64M; does that affect timeout? Only if your query exceeds the packet size – you’ll get “Packet too large” instead of a timeout.


Conclusion

A MySQL connection timeout in n8n is almost always a network or server‑configuration issue, not a bug in the node itself. By confirming raw connectivity, extending the node’s **Connect Timeout**, and aligning MySQL’s wait_timeout/interactive_timeout with your workflow latency, you eliminate the most common failure points. When TLS is required, ensure the full certificate chain is available and correctly referenced. Following the checklist above guarantees a robust, production‑ready MySQL integration that respects both security and performance constraints.

Leave a Comment

Your email address will not be published. Required fields are marked *