I can't seem to understand the documentation in http://strapi.io/documentation/configuration#databases
How to connect to MySqlDB? Where in databases.json do i set all my db settings like user: root, pwd: secret123, host: 192.12.2.123, etc.?
To connect Strapi with MySQL, you have to make sure that the authentication plugin for our root user is mysql_native_password . Currently, Strapi doesn't support the auth plugin that comes with MySQL 8.0.
By default, Strapi uses the SQLite for content storage, but Strapi is not only limited to using SQLite as the database. It can be configured to use other databases like MySQL, MariaDB, PostgreSQL, etc.
You should add a new connection like this:
{
"orm": {
"adapters": {
"mysql": "sails-mysql"
},
"defaultConnection": "default",
"connections": {
"someMysqlServer": {
"adapter": "mysql",
"host": "YOUR_MYSQL_SERVER_HOSTNAME_OR_IP_ADDRESS",
"user": "YOUR_MYSQL_USER",
"password": "YOUR_MYSQL_PASSWORD",
"database": "YOUR_MYSQL_DB"
}
}
}
}
The current version of Strapi is based on Waterline so if you can't find the right info in the documentation, take a look at the Waterline/Sails documentation as well.
Solution for 2020
yarn add sails-mysql
or npm install sails-mysql
yarn add mysql
or npm install mysql
<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,
},
},
},
});
yarn build
to rebuild your CMS.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With