Platform.sh is now Upsun. Click here to learn more
Upsun Fixed User Documentation

Configure MySQL for Strapi on Upsun Fixed

Try Upsun for 15 days
After that, enjoy the same, game-changing Upsun features for less with the First Project Incentive!¹ A monthly $19 perk!
Activate your 15-day trial
¹Terms and conditions apply

Strapi can be configured to use MySQL as its default database. You can choose MySQL when installing your app by selecting custom and MySQL when asked for the installation type. Or you can just configure your existing Strapi application to use MySQL. To configure a MySQL database for Strapi on Upsun Fixed, follow these steps.

  1. Install the Node.js MySQL driver

    yarn add mysql
  2. Replace the PostgreSQL configuration in your .platform/services.yaml file with the following:

    .platform/services.yaml
    mysql:
      type: oracle-mysql:8.0
      disk: 256

    Note that the minimum disk size for MySQL/Oracle MySQL is 256MB.

  3. In your .platform.app.yaml file, replace the relationship name to match the MySQL database you added:

    .platform.app.yaml
    relationships:
      mysqldatabase:
        service: "mysql"
        endpoint: "mysql"
  4. In the config folder, locate the database.js file, and replace its content with the following:

    const config = require("platformsh-config").config();
    const path = require("path");
    
    let dbRelationship = "mysqldatabase";
    
    // Strapi default sqlite settings.
    let pool = {};
    let connection = {
      connection: {
        client: "sqlite",
        connection: {
          filename: path.join(
            __dirname,
            "..",
            process.env.DATABASE_FILENAME || ".tmp/data.db"
          ),
        },
        useNullAsDefault: true,
      },
    };
    
    if (config.isValidPlatform() && !config.inBuild()) {
      // Upsun Fixed database configuration.
      try {
        const credentials = config.credentials(dbRelationship);
        console.log(
          `Using Upsun Fixed configuration with relationship ${dbRelationship}.`
        );
    
        pool = {
          min: 0,
          max: 10,
          acquireTimeoutMillis: 600000,
          createTimeoutMillis: 30000,
          idleTimeoutMillis: 20000,
          reapIntervalMillis: 20000,
          createRetryIntervalMillis: 200,
        };
    
        connection = {
          connection: {
            client: "mysql",
            connection: {
              host: credentials.ip,
              port: credentials.port,
              database: credentials.path,
              user: credentials.username,
              password: credentials.password,
              ssl: false,
            },
            debug: false,
            pool,
          },
        };
      } catch (e) {
        // Do nothing if 'pg' relationship isn't found.
        // Database configuration will fall back on the SQLite defaults.
      }
    } else {
      if (config.isValidPlatform()) {
        // Build hook configuration message.
        console.log(
          "Using default configuration during Upsun Fixed build hook until relationships are available."
        );
      } else {
        // Strapi default local configuration.
    
        console.log(
          "Not in a Upsun Fixed Environment. Using default local sqlite configuration."
        );
      }
    }
    // strapi-api/config/database.js
    module.exports = ({ env }) => connection;

This setting deploys your Strapi application with a MySQL database. If you don’t specify a MySQL service in your .platform/services.yaml file or the Strapi application is run on a local machine the default SQLite database is used.