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 \
--env MYSQL_ROOT_PASSWORD=<PASSWORD> \
--env MYSQL_ROOT_HOST=172.0.0.0/255.0.0.0 \
--env MYSQL_DATABASE=<DATABASE> \
--volume $pwd/mysql-data:/var/lib/mysql \
--network dbnet \
mysql/mysql-server:5.7


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 \
-e DB_MYSQLDB_HOST=<DBNET IP> \
-e DB_MYSQLDB_PORT=3306 \
-e DB_MYSQLDB_USER=<USER> \
-e DB_MYSQLDB_PASSWORD=<PASSWORD> \
--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

1 Like

Having a bit of the same issue here with MySQL. I am trying to move to a new sql server - but I can not make it play nice at all…

kubectl logs -n n8nautomation n8napp-79994d8b74-5dmnr
2023-01-27T23:39:44.378Z | info | Initializing n8n process “{ file: ‘start.js’, function: ‘run’ }”

That is the only event at all in the logs - just dies - even with logging set to debug. Interestinly enough, I get the same error if I have the incorrect username on the current server - so my best guess is something is miss typed; but I can not find it at all for the life of me. I really wish there was a way to get more from the crash event.

Can you check that the host and port are correct, I was checking an issue yesterday and ran into the same problem when it couldn’t connect.

Actually worked it out… It was username.

Mariadb on azure (10.3) is requiring username@server in the username feild for most divers… Like it wasn’t required for phpipam or ombi, but was for this and a couple of other things… Errors varied, but the total crash was the strangest

1 Like

The total crash is a bit odd, we could do with improving the error message there rather than just exiting.

1 Like

i solve it by using the root login of prostgres because my log postgress with a no-root user can’t create a table.

1 Like

I had exactly the same issue as here, the app was crashing without any logging even with N8N_LOG_LEVEL=debug

What helped me is setting N8N_DIAGNOSTICS_ENABLED=false, now the logs started showing up and helped me debug the issue.

2 Likes

Helped to see the logs. Thanks

1 Like

Hi, I’m having the same problem. I’m using N8N version 0.218.0 with MySQL 5.7.

I had two problem

  1. In my database don’t had permission, solved this using
    GRANT ALL PRIVILEGES ON n8n_database.* TO 'devops'@'%';
  2. The version deployed initially was 0.218.0 and for some reason, redeploy pulled the latest version generating the crash.

Everything is working now, I hope this helps anybody.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.