# 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

Path — ./config/database.js.

  • connection (object): Database configuration options passed to Knex.js (opens new window)
    • client (string): Database client to create the connection. sqlite or postgres or mysql.
    • connection (object): Database connection information
      • host (string): Database host name. Default value: localhost.
      • port (integer): Database port.
      • database (string): Database name.
      • username (string): Username used to establish the connection.
      • password (string): Password used to establish the connection.
      • timezone (string): Set the default behavior for local time. Default value: utc Timezone options (opens new window).
      • schema (string): Set the default database schema. Used only for Postgres DB.
      • ssl (boolean/object): For ssl database connection. Object is used to pass certificate files as strings.
    • useNullAsDefault (boolean): Will use NULL as a default value Used only for SQLite
    • debug (boolean): Show database exchanges and errors.
    • pool (object optional): Tarn.js (opens new window) database pooling options
      • min (integer): Minimum number of database connections to keepalive Default value: 0
      • max (integer): Maximum number of database connections to keepalive Default value: 10
      • acquireTimeoutMillis (integer): Time in ms before timing out a database connection attempt
      • createTimeoutMillis (integer): Time in ms before timing out a create query attempt
      • destroyTimeoutMillis (integer): Time in ms before timing out a destroy query attempt
      • idleTimeoutMillis (integer): Time in ms before free database connections are destroyed
      • reapIntervalMillis (integer): Time in ms to check for idle database connections to destroy
      • createRetryIntervalMillis (integer): Time in ms to idle before retrying failed create actions
      • afterCreate (function): Callback function to execute custom logic when the pool acquires a new connection. See the Knex.js documentation (opens new window) for more information
  • settings (object): Strapi specific database settings
    • forceMigration (boolean): Enable or disable the forced database migration. Default value: true.

# Configuration Examples

# Configuration in database

Configuration files are not multi server friendly. So we created a data store for config you will want to update in production.

# 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 config is environment agnostic).
  • type (string): Sets if your config is for an api, plugin or core. By default it's core.
  • name (string): You have to set the plugin or api name if type is api or plugin.
  • 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.