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:
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:
-
Connect to the CLI container.
docker compose run --rm deploy bash -
Connect to the database with a username and password.
mysql --host=db --user=magento2 --password=magento2If you use the split database architecture:
mysql --host=db-quote --user=magento2 --password=magento2mysql --host=db-sales --user=magento2 --password=magento2 -
Verify the version of the database service.
SELECT VERSION(); +--------------------------+ | VERSION() | +--------------------------+ | 10.0.38-MariaDB-1~xenial | +--------------------------+
To connect to the database port:
-
Find the port used by the database. The port can change each time you restart Docker.
docker compose psSample response:
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 -
Connect to the database with port information from the previous step.
mysql -h127.0.0.1 -P32769 -umagento2 -pmagento2If you use the split database architecture, use the following ports to connect:
For 'db-quote' service:
mysql -h127.0.0.1 -32873 -umagento2 -pmagento2For 'db-sales' service:
mysql -h127.0.0.1 -32874 -umagento2 -pmagento2 -
Verify the version of the database service.
SELECT VERSION(); +--------------------------+ | VERSION() | +--------------------------+ | 10.0.38-MariaDB-1~xenial | +--------------------------+
Import a database dump
data-variant=warning
data-slots=text
To import a database dump into the Docker environment:
-
Create a local copy of the remote database.
magento-cloud db:dump<!-- <InlineAlert variant="info" slots="text"/> -->
The
magento-cloud db:dumpcommand runs the mysqldump command with the--single-transactionflag, which allows you to back up your database without locking the tables. -
Place the resulting SQL file into the
.docker/mysql/docker-entrypoint-initdb.dfolder.The
ece-toolspackage imports and processes the SQL file the next time you build and start the Docker environment using thedocker compose upcommand. When you build, you must add the--with-entrypointoption to theece-docker build:composecommand. This option configures the directories for the imported database. See Service configuration options.
data-variant=help
data-slots=text
.sql.gz file using the .docker/mnt directory and import it inside the Docker container.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:
db:
volumes:
- path/to/custom.my.cnf:/etc/mysql/conf.d/custom.my.cnf
Add configuration values to the docker-compose.override.yml file:
db:
environment:
- innodb-buffer-pool-size=134217728
data-variant=info
data-slots=text
<!--Link definitions-->