Home > Mobile >  Strapi v4 use MySql Database in Production
Strapi v4 use MySql Database in Production

Time:02-02

How to add configuration that Strapi use mysql in production and sqlite for local development?

Strapi v4

CodePudding user response:

  1. Add mysql driver yarn add mysql or npm install mysql
  2. Add dotenv yarn add dotenv or npm install dotenv
  3. Create new file: config/env/production/database.js
  4. Add the following content:
module.exports = ({ env }) => ({   connection: {
 client: "mysql",
 connection: {
   host: env("DATABASE_HOST", "localhost"),
   port: env("DATABASE_PORT", 3306),
   database: env("DATABASE_NAME", "default"),
   user: env("DATABASE_USERNAME", "root"),
   password: env("DATABASE_PASSWORD", ""),
 },
 useNullAsDefault: true,   
 }, 
});
  1. Add your config to the .env File in Production.
  2. Strapi will pick the correct configuration.

CodePudding user response:

1.Add MySQL driver npm install mysql

2.Add sqlite3 driver npm install sqlite3

3.Set you environment file we do it like this

3.1.    On dev set ENV_PATH=           
  •  Tags:  
  • Related