
n8n’s MySQL and PostgreSQL nodes let a workflow query, insert and update rows directly in a database. The node is the easy part. The hard part is reaching the database from the container n8n runs in, and doing it without opening the database to the world.
Where the database lives
| Where it is | How n8n gets there |
| In the same compose file, another container | By the service name, on the Docker network. See Docker Compose: an application with its database. |
| On the same VPS, outside Docker | localhost inside the container is the container itself, not the VPS. Use the address Docker gives a container to reach its host (Docker’s documentation explains it) and make sure the database listens on that interface. |
| On another VPS | Over a private network, or by opening the port only to the n8n IP. See installing PostgreSQL on a VPS. |
| On a shared hosting plan | Ports 3306 and 5432 are not open from outside. You get there through an SSH tunnel. See the SSH tunnel, step by step, and what “Remote MySQL” does in letting an outside address reach your MySQL. |
Setting up the connection
|
|
|
|
|
| Never paste into SQL text anything that came from outside (a form field, a webhook body, an e-mail subject). Whoever controls that text controls your database. Use the node parameters and a user without the right to delete. |
Two common mix-ups
| Mix-up | The truth |
| The database n8n uses inside is my database | They are two things. n8n keeps its workflows and executions in a database of its own (by default an internal file; the project documentation describes how to use PostgreSQL). The nodes connect to your database, the one with the business data. |
| MySQL and MariaDB are the same | Shared hosting plans use MariaDB, which speaks the same protocol. The MySQL node usually works; see MySQL or MariaDB: which one runs here. |
| Accents turn into question marks | It is the character set. See character sets: utf8mb4. |
| Back up the database before the first workflow that writes to it. See backing up with mysqldump and pg_dump. |
|
Need a VPS to run n8n and the database on? See the VPS servers |
|
SEE ALSO Reaching MySQL or PostgreSQL through an SSH tunnel Creating a database user and giving it the right privileges |
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from 5.940,00 Kz/mo (3-year plan, with coupon) See plans |
- 0 Users Found This Useful











