Edit in GitHubLog an issue

Manage the database

The Cloud Docker development environment provides MySQL services through a MariaDB (default) or MySQL database deployed to the Docker database container.

You connect to the database using docker compose commands. You can also import data from an existing Adobe Commerce on cloud infrastructure project into the database container using the magento-cloud db:dump command.

Connect to the database

You can connect to the database through the Docker container or through the database port. Before you begin, locate the database credentials in the database section of the .docker/config.php file.

The procedures in this topic use the following default credentials:

Copied to your clipboard
return [
'MAGENTO_CLOUD_RELATIONSHIPS' => base64_encode(json_encode([
'database' => [
[
'host' => 'db',
'path' => 'magento2',
'password' => 'magento2',
'username' => 'magento2',
'port' => '3306'
],
],
// The following configuration is available if you are using the split database architecture.
'database-quote' => [
[
'host' => 'db-quote',
'path' => 'magento2',
'password' => 'magento2',
'username' => 'magento2',
'port' => '3306'
],
],
'database-sales' => [
[
'host' => 'db-sales',
'path' => 'magento2',
'password' => 'magento2',
'username' => 'magento2',
'port' => '3306'
],
],

To connect to the database using Docker commands:

  1. Connect to the CLI container.

    Copied to your clipboard
    docker compose run --rm deploy bash
  2. Connect to the database with a username and password.

    Copied to your clipboard
    mysql --host=db --user=magento2 --password=magento2

    If you use the split database architecture:

    Copied to your clipboard
    mysql --host=db-quote --user=magento2 --password=magento2
    Copied to your clipboard
    mysql --host=db-sales --user=magento2 --password=magento2
  3. Verify the version of the database service.

    Copied to your clipboard
    SELECT VERSION();
    +--------------------------+
    | VERSION() |
    +--------------------------+
    | 10.0.38-MariaDB-1~xenial |
    +--------------------------+

To connect to the database port:

  1. Find the port used by the database. The port can change each time you restart Docker.

    Copied to your clipboard
    docker compose ps

    Sample response:

    Copied to your clipboard
    Name Command State Ports
    --------------------------------------------------------------------------------------------------
    magento-cloud_db_1 docker-entrypoint.sh mysqld Up 0.0.0.0:32769->3306/tcp
    # The following lines are available if you are using the split database architecture.
    magento-cloud_db-quote_1 docker-entrypoint.sh mysqld Up 0.0.0.0:32873->3306/tcp
    magento-cloud_db-sales_1 docker-entrypoint.sh mysqld Up 0.0.0.0:32874->3306/tcp
  2. Connect to the database with port information from the previous step.

    Copied to your clipboard
    mysql -h127.0.0.1 -P32769 -umagento2 -pmagento2

    If you use the split database architecture, use the following ports to connect:

    For 'db-quote' service:

    Copied to your clipboard
    mysql -h127.0.0.1 -32873 -umagento2 -pmagento2

    For 'db-sales' service:

    Copied to your clipboard
    mysql -h127.0.0.1 -32874 -umagento2 -pmagento2
  3. Verify the version of the database service.

    Copied to your clipboard
    SELECT VERSION();
    +--------------------------+
    | VERSION() |
    +--------------------------+
    | 10.0.38-MariaDB-1~xenial |
    +--------------------------+

Import a database dump

To import a database dump into the Docker environment:

  1. Create a local copy of the remote database.

    Copied to your clipboard
    magento-cloud db:dump

    The magento-cloud db:dump command runs the mysqldump command with the --single-transaction flag, which allows you to back up your database without locking the tables.

  2. Place the resulting SQL file into the .docker/mysql/docker-entrypoint-initdb.d folder.

    The ece-tools package imports and processes the SQL file the next time you build and start the Docker environment using the docker compose up command. When you build, you must add the --with-entrypoint option to the ece-docker build:compose command. This option configures the directories for the imported database. See Service configuration options.

Customize the database container

You can inject a MySQL configuration into the database container at creation by adding the configuration to the docker-compose-override.yml file. Add the custom values using an included my.cnf file, or add the correct variables directly to the override file as shown in the following examples.

Add a custom my.cnf file to the docker-compose.override.yml file:

Copied to your clipboard
db:
volumes:
- path/to/custom.my.cnf:/etc/mysql/conf.d/custom.my.cnf

Add configuration values to the docker-compose.override.yml file:

Copied to your clipboard
db:
environment:
- innodb-buffer-pool-size=134217728
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.