iPaaS Group

n8n · MySQL node

Can't connect to a local MySQL server when using Docker

Short answer

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

n8n error
Can't connect to a local MySQL server when using Docker

02Likely 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

  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.

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.

Prompt
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-docker

Nothing 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

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