Connecting to MySql DB in strapi

Viewed 13997
3 Answers

Solution for 2020

  1. Add client:
  • Strapi < 3.2.5: yarn add sails-mysql or npm install sails-mysql
  • Strapi >= 3.2.5: yarn add mysql or npm install mysql
  1. Change config <project>/config/database.js (for development) or <project>/config/env/production/database.js (for production)
module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'bookshelf',
      settings: {
        client: "mysql",
        host: env('DATABASE_HOST', 'localhost'),
        port: env('DATABASE_PORT', 3306),
        database: env('DATABASE_NAME', 'default'),
        username: env('DATABASE_USERNAME', 'root'),
        password: env('DATABASE_PASSWORD', ''),
      },
      options: {
        useNullAsDefault: true,
      },
    },
  },
});
  1. Also may be you'll need to run yarn build to rebuild your CMS.
Related