# Database configuration
The ./config/database.js
file is used to define database connections that will be used to store the application content.
🤓 Supported databases
The CLI installation guide details supported database and versions.
# Configuration structure
The ./config/database.js
accepts 2 main configuration objects:
connection
for database configuration options passed to Knex.js (opens new window)settings
for Strapi-specific database settings
# connection
configuration object
Parameter | Description | Type | Default |
---|---|---|---|
client | Database client to create the connection. sqlite or postgres or mysql . | String | - |
connection | Database connection information | Object | - |
debug | Show database exchanges and errors. | Boolean | false |
useNullAsDefault Optional, only for SQLite | Use NULL as a default value | Boolean | true |
pool Optional | Database pooling options | Object | - |
acquireConnectionTimeout Optional | How long knex will wait before throwing a timeout error when acquiring a connection (in milliseconds) | Integer | 60000 |
# Connection parameters
The connection.connection
object found in ./config/database.js
is used to pass database connection information and accepts the following parameters:
Parameter | Description | Type |
---|---|---|
host | Database host name. Default value: localhost . | String |
port | Database port | Integer |
database | Database name. | String |
user | Username used to establish the connection | String |
password | Password used to establish the connection | String |
timezone | Set the default behavior for local time. Default value: utc Timezone options (opens new window) | String |
schema | Set the default database schema. Used only for Postgres DB. | String |
ssl | For SSL database connection. Use an object to pass certificate files as strings. | Boolean or Object |
# Database pooling options
The connection.pool
object optionally found in ./config/database.js
is used to pass Tarn.js (opens new window) database pooling options and accepts the following parameters:
Parameter | Description | Type | Default |
---|---|---|---|
min | Minimum number of database connections to keepalive | Integer | 0 |
max | Maximum number of database connections to keepalive | Integer | 10 |
acquireTimeoutMillis | Time in milliseconds before timing out a database connection attempt | Integer | - |
createTimeoutMillis | Time in milliseconds before timing out a create query attempt | Integer | - |
destroyTimeoutMillis | Time in milliseconds before timing out a destroy query attempt | Integer | - |
idleTimeoutMillis | Time in milliseconds before free database connections are destroyed | Integer | - |
reapIntervalMillis | Time in milliseconds to check for idle database connections to destroy | Integer | - |
createRetryIntervalMillis | Time in milliseconds to idle before retrying failed create actions | Integer | - |
afterCreate | Callback function to execute custom logic when the pool acquires a new connection. See the Knex.js documentation (opens new window) for more information | Function | - |
# settings
configuration object
The settings
object found in ./config/database.js
is used to configure Strapi-specific database settings and accepts the following parameter:
Parameter | Description | Type | Default |
---|---|---|---|
forceMigration | Enable or disable the forced database migration. | Boolean | true |
# Configuration examples
# Configuration in database
Configuration files are not multi-server friendly. To update configurations in production you can use a data store to get and set settings.
# Get settings
environment
(string): Sets the environment you want to store the data in. By default it's current environment (can be an empty string if your configuration is environment agnostic).type
(string): Sets if your configuration is for anapi
,plugin
orcore
. By default it'score
.name
(string): You have to set the plugin or api name iftype
isapi
orplugin
.key
(string, required): The name of the key you want to store.
// strapi.store(object).get(object);
// create reusable plugin store variable
const pluginStore = strapi.store({
environment: strapi.config.environment,
type: 'plugin',
name: 'users-permissions',
});
await pluginStore.get({ key: 'grant' });
# Set settings
value
(any, required): The value you want to store.
// strapi.store(object).set(object);
// create reusable plugin store variable
const pluginStore = strapi.store({
environment: strapi.config.environment,
type: 'plugin',
name: 'users-permissions'
});
await pluginStore.set({
key: 'grant',
value: {
...
}
});
# Databases installation guides
Strapi gives you the option to choose the most appropriate database for your project. It currently supports PostgreSQL, SQLite, MySQL and MariaDB.
The following documentation covers how to install SQLite locally (for development purposes):
✋ CAUTION
Installation guides for other databases (MySQL, MariaDB) are being reworked. Contributions (opens new window) are most welcome.