The following below steps need to follow.
before applying below command you must be Magento Cloud Login in any environment like Integration, Staging, Production etc.
magento-cloud login
Step [1] – Run, The following below Command Magento Cloud SSH to log in to the remote environment.
magento-cloud ssh
Step [2] – Run below vi command to open app/etc/env.php
vi app/etc/env.php
env.php file, need to check db connection part
Below is Magento 2.4.x Commerce Cloud default env.php format
<?php
return [
'cache' => [
'frontend' => [
'default' => [
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => 'redis.internal',
'port' => 6379,
'database' => 1
]
],
'page_cache' => [
'backend' => 'Cm_Cache_Backend_Redis',
'backend_options' => [
'server' => 'redis.internal',
'port' => 6379,
'database' => 2
]
]
],
'graphql' => [
'id_salt' => 'AdS6J2N9YNbRAlhfzjci5swps1boeebc'
]
],
'MAGE_MODE' => 'production',
'cache_types' => [
'compiled_config' => 1,
'config' => 1,
'layout' => 1,
'block_html' => 1,
'collections' => 1,
'reflection' => 1,
'db_ddl' => 1,
'eav' => 1,
'customer_notification' => 1,
'config_integration' => 1,
'config_integration_api' => 1,
'full_page' => 1,
'target_rule' => 1,
'config_webservice' => 1,
'translate' => 1,
'vertex' => 1
],
'cron' => [
],
'backend' => [
'frontName' => 'admin'
],
'remote_storage' => [
'driver' => 'file'
],
'queue' => [
'consumers_wait_for_messages' => 0
],
'db' => [
'connection' => [
'default' => [
'host' => 'database.internal',
'username' => 'user',
'dbname' => 'main',
'password' => ''
],
'indexer' => [
'host' => 'database.internal',
'username' => 'user',
'dbname' => 'main',
'password' => ''
]
]
],
'crypt' => [
'key' => 'f18dacf326865a257d00768151d46c03'
],
'resource' => [
'default_setup' => [
'connection' => 'default'
]
],
'x-frame-options' => 'SAMEORIGIN',
'session' => [
'save' => 'redis',
'redis' => [
'host' => 'redis.internal',
'port' => 6379,
'database' => 0,
'disable_locking' => 1
]
],
'lock' => [
'provider' => 'db',
'config' => [
'prefix' => null
]
],
'directories' => [
'document_root_is_pub' => true
],
'downloadable_domains' => [
'master-7rqtwti-a4kqty5oswp5a.ap-3.magentosite.cloud'
],
'install' => [
'date' => 'Tue, 18 Jan 2022 04:02:32 +0000'
],
'static_content_on_demand_in_production' => 0,
'force_html_minification' => 1,
'cron_consumers_runner' => [
'cron_run' => false,
'max_messages' => 10000,
'consumers' => [
],
'multiple_processes' => [
]
],
'system' => [
'default' => [
'catalog' => [
'search' => [
'engine' => 'elasticsearch7',
'elasticsearch7_server_hostname' => 'http://elasticsearch.internal',
'elasticsearch7_server_port' => 9200
]
]
]
]
];
If db connection part as below, need to run below three command to open Cloud Commerce / Enterprise Database
$MAGENTO_CLOUD_RELATIONSHIPS variable. Echo
echo $MAGENTO_CLOUD_RELATIONSHIPS | base64 -d | json_pp
mysql -h database.internal -u user
Each Command has been described properly in below
'db' => [
'connection' => [
'default' => [
'host' => 'database.internal',
'username' => 'user',
'dbname' => 'main',
'password' => ''
],
'indexer' => [
'host' => 'database.internal',
'username' => 'user',
'dbname' => 'main',
'password' => ''
]
]
],
Step [2.1] – Run Command Magento Cloud RELATIONSHIPS
$MAGENTO_CLOUD_RELATIONSHIPS variable. Echo
Step [2.2] – Run Command Magento Cloud RELATIONSHIPS with additional variable
echo $MAGENTO_CLOUD_RELATIONSHIPS | base64 -d | json_pp
display Redis Cache, Database Elasticsearch details as below
Step [2.3] – Run MYSQL Database Access Command
mysql -h database.internal -u user
Displaying MYSQL / MariaDB Environment
show databases;
Displaying all Database [ MYSQL / MariaDB ] information, as here
MYSQL main database already created.
Step [2.4] – Run MYSQL Use Command
use databasename;
Step [3] – If db connection part [env.php] as below, need to run below three command to open Cloud Commerce / Enterprise Database
'db' =>
array (
'connection' =>
array (
'default' =>
array (
'host' => '127.0.0.1',
'username' => 'j272qgwkbtefk_stg',
'dbname' => 'mage2db',
'password' => ']4Tke3.IMO=\/9@',
'model' => 'mysql4',
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
'driver_options' =>
array (
1014 => false,
),
),
'indexer' =>
array (
'host' => '127.0.0.1',
'username' => 'j272qgwkbtefk_stg',
'dbname' => 'mage2db',
'password' => ']4Tke3.IMO=\/9@',
'model' => 'mysql4',
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
),
),
'table_prefix' => '',
),
Step [4] – Need to run below command with host
mysql -h 127.0.0.1 -u j272qgwkbtefk_stg -p
Some db connection part having Port, port=3306
mysql -P 3306 -h 127.0.0.1 -u john -p
Step [5] – By Using below direct command
magento-cloud db:sql
Step [6] – Need to run below command to check disk usage of the MySQL service
magento-cloud db:size
Step [6] – Need to run below command to Database Dump
magento-cloud db:dump