-
I have an error in the two MySQL drivers: I have access by express using knex in mysql and mysq2 drivers |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
What you want to do is add the values you placed inside your MySQL config inside the .env file as the following:
The premise of environment variables is to keep things like this secret and outside of the code. The Once you've updated your mysql: {
client: 'mysql',
connection: {
host: Env.get('MYSQL_HOST'),
port: Env.get('MYSQL_PORT'),
user: Env.get('MYSQL_USER'),
password: Env.get('MYSQL_PASSWORD', ''),
database: Env.get('MYSQL_DB_NAME'),
},
migrations: {
naturalSort: true,
},
healthCheck: false,
debug: false,
}, This will use the It's also recommended to add these to your DB_CONNECTION: Env.schema.string(),
MYSQL_HOST: Env.schema.string({ format: 'host' }),
MYSQL_PORT: Env.schema.number(),
MYSQL_USER: Env.schema.string(),
MYSQL_PASSWORD: Env.schema.string.optional(),
MYSQL_DB_NAME: Env.schema.string(), You can read through the Environment Variables documentation for more information. |
Beta Was this translation helpful? Give feedback.
-
You have to use the defined env variables with Env.get. Like: host: Env.get('HOST') |
Beta Was this translation helpful? Give feedback.
-
It's working. You can close as resolved. |
Beta Was this translation helpful? Give feedback.
Env.get()
takes a lookup key as the first argument that it'll use to grab a value from the.env
file. You can use the second argument for fallback values, though I'd recommend the below over that.What you want to do is add the values you placed inside your MySQL config inside the .env file as the following:
The premise of environment variables is to keep things like this secret and outside of the code. The
.env
file shouldn't be committed to GitHub or any other repository.Once you've updated your
.env
file to the above, reset your MySQL config back to how it initially …