How to Access Magento Cloud (projects) Databases in your local Machine by Terminal

Below steps will help you to access the magento cloud Database in your local machine with basic magento terminal commands.

Install magento Cloud CLI:

  1. Open terminal and Go to >cd /var/www/
  2. Install magento cloud by following command,
    >var/www>curl -sS https://accounts.magento.cloud/cli/installer | php
  3. Add CLI to basefile,
    >var/www>export PATH=$PATH:$HOME/.magento-cloud/bin
  4. Update base profile
    >var/www>~/.bash_profile
  5. Go to >var/www>magento-cloud
    Once you execute “magento-cloud” command, system will show below message in your terminal,
    [root@localhost www]# magento-cloud
    Welcome to Magento Cloud!
    Loading projects…
    LoginRequiredException]
    Authentication is required.
    Please log in by running:
    magento-cloud login
    To log in using an API token, run: magento-cloud auth:api-token-login
  6. To resolve this issue, you have to generate token from your cloud account.
  7. API Token Generation, login https://accounts.magento.cloud/ go to Account Settings > API Token > Create an API token.

Way : 1 By Browser. Once you execute below command, system will provide URL. Using that URL (UI page) you can login.
var/www>magento-cloud login

Way : 2 Login vai Terminal:
>var/www>magento-cloud auth:api-token-login

Sample Screen:
Please enter an API token:
>

The API token is valid.
You are logged in.

Generating SSH certificate...
A new SSH certificate has been generated.
It will be automatically refreshed when necessary.
Do you want to create an SSH configuration file automatically? [Y/n] y
Configuration file created successfully: /root/.ssh/config

Username: <Cloud Account UserName>
Email address: <Cloud Account EmailID>
  1. Now your system is ready to login with “magento-cloud” command.
    var/www>magento-cloud
    Now system will list out all your cloud project (mapped with your cloud account).
  2. var/www>magento-cloud db:sql
    With this command system will list out all your cloud project databases. Select your project Database & environment which you want to access.

Ex:
Enter a number to choose a project:
Enter a number to choose an environment:

  1. Select Environment & start use/run your mysql query.

Note: magento-cloud list –> This command is list out all CLI sub command.
Access Magento Cloud Project Database in your local Machine (Terminal), Cloud CLI command Magento,Cloud CLI command Magento2, Login cloud database in terminal,
login magento cloud database in our local machine, CLI command magento2, CLI command login DB

More Infor Refer: https://devdocs.magento.com/cloud/reference/cli-ref-topic.html

Wear Mask and Maintain Social Distancing !!!