N8n crashing during container initialization with Docker and MySQL

I’m trying to set up a Docker container for n8n that links to a Docker container of MySQL. I can get the MySQL set up and even link into it through a bridge from another container, but when I try to create an n8n container, the system waits for a few seconds and then closes the container. The next time I try to create the container it says the last session crashed.

The closest thing to an error message I am seeing is:

Initializing n8n process
Last session crashed

I should explain that I am new to docker, n8n, and MySQL and it is a miracle I even got this far. Please explain things in a newbie-friendly way if you could.

docker network create --driver bridge dbnet

docker network inspect dbnet

docker pull mysql/mysql-server:5.7

docker run --name mysql \
--volume $pwd/mysql-data:/var/lib/mysql \
--network dbnet \

mysql -u root -p
CREATE USER '[user]'@'localhost' IDENTIFIED WITH mysql_native_password BY '[password]';
GRANT ALL PRIVILEGES ON *.* TO '[user]'@'%' IDENTIFIED BY '[password]' with grant option;

docker run --rm -it --name n8n -p 5678:5678 \
-e DB_TYPE=mysqldb -e DB_MYSQLDB_DATABASE=n8n \
--network dbnet \
-v ~/.n8n:/home/node/.n8n n8nio/n8n \
n8n start

Running n8n via [Docker, n8n, MySQL5.7]:

I’m using MySQL 5.7 due to an issue with MySQL encoding the root password in a way that my other container cannot read.

Hi @Ryan_Corp, welcome to the community!

I am sorry to hear you’re having trouble. Can you share the output you are seeing before the n8n container crashes? This should hopefully have a few more details.

On a different note, I think we are considering dropping support for MySQL as an n8n backend database at some point. So you might want to consider using PostgreSQL instead. n8n/docker/compose/withPostgres at master · n8n-io/n8n · GitHub would have an example configuration for docker compose that should help getting started with this database.

@MutedJam Hello.

Please don’t drop support for MySQL as backend database. We use it extensively. Just leave it as an option. Not everyone is familiar with PostgreSQL etc.

And it’s not that we have it on a single node. We use MySQL that is part of a failover cluster etc. We can’t spin for example a PostgreSQL node because then we have to create a plan for a cluster network too etc.

Hi @Mulen, tbf I don’t have any details and am not familiar with the exact plans. It’s just something I heard being discussed. I imagine there’d definitely be plenty of time to prepare if this happens at all (and there definitely won’t be a forced upgrade, so you can always continue using an existing setup).

The main argument against was that supporting MySQL costs a lot of time time and effort on writing and debugging migrations, especially around behavior specific to MySQL. There are pro arguments as well of course.

1 Like
Initializing n8n process
Last session crashed

This is all I saw. The n8n container didnt give any other output. That being said, I will try to switch to a postgreSQL setup and see if that works. Luckily Im still in the early phases of this project so nothing is set in stone.

Hi, it is happening the same for me. Docker + postgresql setup on local machine.

I am only getting this error.

exited with code 1
| Initializing n8n process
| Last session crashed