Connect to the database
There are two ways to connect to the database. Before you begin, you can find the database credentials in the database
section of the .docker/config.php
file. The examples use the following default credentials:
Filename:
.docker/config.php
1
2
3
4
5
6
7
8
9
10
11
return [
'MAGENTO_CLOUD_RELATIONSHIPS' => base64_encode(json_encode([
'database' => [
[
'host' => 'db',
'path' => 'magento2',
'password' => 'magento2',
'username' => 'magento2',
'port' => '3306'
],
],
To connect to the database using Docker commands:
-
Connect to the CLI container.
1
docker-compose run deploy bash
-
Connect to the database with a username and password.
1
mysql --host=db --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:
-
Find the port used by the database. The port may change each time you restart Docker.
1
docker-compose ps
Sample response:
1 2 3
Name Command State Ports -------------------------------------------------------------------------------------------------- mc-master_db_1 docker-entrypoint.sh mysqld Up 0.0.0.0:32769->3306/tcp
-
Connect to the database with port information from the previous step.
1
mysql -h127.0.0.1 -p32769 -umagento2 -pmagento2
-
Verify the version of the database service.
SELECT VERSION(); +--------------------------+ | VERSION() | +--------------------------+ | 10.0.38-MariaDB-1~xenial | +--------------------------+