fbpx

Strapi V4 MySQL Connection for Production

Strapi V4 MySQL Connection for Production

This tutorial explains how to configure Strapi v4 to use MySQL in production mode

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,
  },
});
5. Add your config to the .env File in Production.
6. Strapi will pick the correct configuration.


For more Information visit:
https://docs.strapi.io/developer-docs/latest/
Related Posts