n8n · MySQL node
Can't connect to a local MySQL server when using Docker
When n8n cannot connect to a local MySQL server with Docker involved, the Host in the MySQL credential or the network setup does not match where MySQL and n8n run. MySQL must listen on 0.0.0.0, and the Host must be localhost, host.docker.internal or the MySQL container name depending on the setup.
VerifiedLast verified
01Error text
Can't connect to a local MySQL server when using Docker02Likely causes
- The network configuration does not match where MySQL and n8n run.
- MySQL is not bound to
0.0.0.0, the port is not published, or the containers are not on the same network.
03How to fix it
- If only MySQL runs in Docker, make sure it binds to
0.0.0.0and publish the port, for example-p 3306:3306. Set Host tolocalhostin the MySQL credential. - If only n8n runs in Docker, bind MySQL to
0.0.0.0on the host. On Linux start n8n with--add-host host.docker.internal:host-gateway(Docker Desktop does this automatically), and set Host tohost.docker.internal. - If they run in separate containers, bind MySQL to
0.0.0.0, put both containers on the same user-defined bridge network, and set Host to the MySQL container name. - If they run in the same container, set Host to
localhost.
04Fix it with AI
Copy this prompt into Claude Code, ChatGPT or any AI assistant. It already holds the error, the likely causes and the fix steps, so the assistant starts from what is known instead of guessing.
I'm getting this error in n8n (MySQL node):
Can't connect to a local MySQL server when using Docker
What it usually means: When n8n cannot connect to a local MySQL server with Docker involved, the Host in the MySQL credential or the network setup does not match where MySQL and n8n run. MySQL must listen on 0.0.0.0, and the Host must be localhost, host.docker.internal or the MySQL container name depending on the setup.
Likely causes:
- The network configuration does not match where MySQL and n8n run.
- MySQL is not bound to 0.0.0.0, the port is not published, or the containers are not on the same network.
Fix steps that usually work:
1. If only MySQL runs in Docker, make sure it binds to 0.0.0.0 and publish the port, for example -p 3306:3306. Set Host to localhost in the MySQL credential.
2. If only n8n runs in Docker, bind MySQL to 0.0.0.0 on the host. On Linux start n8n with --add-host host.docker.internal:host-gateway (Docker Desktop does this automatically), and set Host to host.docker.internal.
3. If they run in separate containers, bind MySQL to 0.0.0.0, put both containers on the same user-defined bridge network, and set Host to the MySQL container name.
4. If they run in the same container, set Host to localhost.
Help me fix it. If you can read my project files, find where this error comes from. If not, ask me for what you need (the failing step, its input, the connection or config). Check the likely causes one by one, tell me which one it is and why, then give me the exact change to make. Do not change anything in production. Reference: https://ipaaserrors.com/n8n/mysql-cant-connect-to-local-server-dockerNothing is sent anywhere from this page. Read what the assistant suggests before you apply it.
iNotes
The docs describe this as a problem and do not quote a fixed error message, so the text above is the docs' own heading.
05Official documentation
→Related errors
- Connection refused (ECONNREFUSED)ECONNREFUSED in the n8n HTTP Request node means the node reached a host but the target port has no listener, most often because of Docker networking on self-hosted n8n. Address the target by a name the container can route to, such as host.docker.internal or the Compose service name.
- Decimal numbers returned as stringsThe n8n MySQL node returns DECIMAL values as strings by default to avoid losing precision. Turn on the Output Decimals as Numbers option to get JavaScript numbers, but leave it off for money, identifiers and values you compare or store again.
Test every fix in a non-production environment before you apply it to production. See how entries are verified.
More for n8n work:Open n8n jobsn8n pay estimates