Database connection

export DB_TYPE=mysqldb
export DB_MYSQLDB_DATABASE=n8n
export DB_MYSQLDB_HOST=mysqldb
export DB_MYSQLDB_PORT=3306
export DB_MYSQLDB_USER=n8n
export DB_MYSQLDB_PASSWORD=n8n

n8n start

i tried to shift db sqlite to mysql it is done but i’m not getting the .env file where it is created in my local system can anyone know ?

Welcome to the community @niteshnigam!

You can simply save it in whatever folder you are starting n8n from. You have to however make sure that it has the correct format. The command export is only needed if you set an environment variable via the command-line. For .env files it is not needed. Meaning the file you have to save would look like this:

DB_TYPE=mysqldb
DB_MYSQLDB_DATABASE=n8n
DB_MYSQLDB_HOST=mysqldb
DB_MYSQLDB_PORT=3306
DB_MYSQLDB_USER=n8n
DB_MYSQLDB_PASSWORD=n8n

Thanks for Quickly reply @jan
but I have run that export command and after that, I am consoling the process.env.DB_TYPE I’m getting the value but I want to see where the .env file is created.

Sorry not sure that I understand what you mean.

You have to create the .env file yourself in the folder you start n8n from (could be any folder) with the content I did send above. n8n will then find the .env file itself and will read its content.

HI @jan, first of all, I cloned the repo and does all things to start n8n and after that, I have created .env file and copied the data as you send above then I again run npm run build and then npm run start but the database is not changed it is still running in SQLite, I want to change DB which is in MySQL and I have given the value in .env file:-
DB_TYPE=mysqldb
DB_MYSQLDB_DATABASE=n8n
DB_MYSQLDB_HOST=localhost
DB_MYSQLDB_PORT=3306
DB_MYSQLDB_USER=root
DB_MYSQLDB_PASSWORD=

can u help me

Unless you want to extend n8n (so actually change its source code) I would advice you to either npm n8n or run it in docker.

Anyway if you really want to run it that way for what reason ever, you have to do that differently. The reason is that if you run “npm run start” it executes cd packages/cli/bin && ./n8n. Meaning the actual folder you run n8n from is packages/cli/bin and it would look for the .env file in there. If you want that it reads the file from the current folder you should rather execute:

./packages/cli/bin/n8n
1 Like