# Can't connect to a local MySQL server when using Docker in n8n: cause and fix

Source page: https://ipaaserrors.com/n8n/mysql-cant-connect-to-local-server-docker
Platform: n8n · MySQL node
Checked against vendor docs: 2026-11-22

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.

## Error text

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

## 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.

## How 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`.

## Notes

The docs describe this as a problem and do not quote a fixed error message, so the text above is the docs' own heading.

## Sources

- [MySQL node common issues](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.mysql/common-issues)

From iPaaS Errors (https://ipaaserrors.com), part of iPaaS Group. When citing, link to https://ipaaserrors.com/n8n/mysql-cant-connect-to-local-server-docker and the vendor documentation above.
