4

I am working on a project based on Magento Commerce Cloud.

Can anyone please guide me on how can I access the database of the staging branch?

Thanks!

5 Answers 5

12

If your goal is to access it using some type of GUI client, you could accomplish this by opening an ssh tunnel using the magento-cloud utility, similar to the above answer:

magento-cloud tunnel:open --project=<PROJECT_ID> --environment=staging

Then run the command magento-cloud tunnel:info to get the appropriate credentials to input into whatever utility you may be trying to use.

[edited] syntax error on "tunnel:open"

4
  • Can you configure something like dbeaver to connect to mysql across a ssh tunnel? Commented Jun 11, 2019 at 0:25
  • I'm not familiar with dbeaver but once the tunnel is open (via the cli tool), any client should be able to connect through it. magento-cloud tunnel:info will give the connection information which would have a port on localhost to connect to as well as a username and password if it is staging or production. Commented Jun 11, 2019 at 16:15
  • should be magento-cloud tunnel:open --project=<PROJECT_ID> --environment=staging but of course one syntax error requires 10 characters to be edited in order to improve the answer. Commented Apr 22, 2020 at 12:17
  • Shorthand arguments: magento-cloud tunnel:open -p PROJECT_ID -e staging
    – Mike Dubs
    Commented Feb 13 at 18:50
3

Try:

SSH to the Integration environment.

magento-cloud ssh

Connect to the database.

mysql -h <db-host> -P <db-port> -p -u <db-user> <db-name>
3
  • Thanks.Do we have any option other than terminal ?
    – S.Venky
    Commented May 21, 2019 at 14:06
  • I think no, as this is managed by aws. I'll update if I got any solution in future
    – Saphal Jha
    Commented May 21, 2019 at 14:11
  • @S.Venky See my answer below
    – Jiyaad.D
    Commented Feb 22, 2022 at 16:32
3

If you using intellij do the following:

Open a tunnel to your required environment:

magento-cloud tunnel:open -e integration

You should see similar output to the below:

SSH tunnel opened to elasticsearch at: http://127.0.0.1:30003
SSH tunnel opened to redis at: redis://127.0.0.1:30004
SSH tunnel opened to database at: mysql://user:@127.0.0.1:30005/main

Copy the MySQL string to the clipboard

mysql://user:@127.0.0.1:30005/main

In Intellij, create a mysql datasource, under the general tab, locate the "URL:" input and paste the mysql string in after the jdbc: text.

Final result should be:

jdbc:mysql://user:@127.0.0.1:30005/main

enter image description here

Click test connection, you should see the success message, next click apply and you should be good to go

enter image description here

2

You can also use the ece-tools package for taking a db dump:

/vendor/bin/ece-tools‌ db-dump
0

I use dbeaver software. It gives you a visual editor

Once the tunnel is open (via the cli tool), any client should be able to connect through it. magento-cloud tunnel:info will give the connection information

https://dbeaver.io/

Connect to MySQL server in Dbeaver

Create new connection button

Select MySQL

In the ‘General’ window this is ‘User name’ and ‘Password’ for databse

User name: MYSQL user name you want to use

Password: Password of the MYSQL user

When you have already filled the required fields click to Next button. After it the second important window appears:

First of all click to the checkbox icon ‘Use SSH Tunnel’ to gain access to the settings. Fields you have to fill in the right way:

HOST/IP: IP of details shown by magento command

User Name: ssh connection user name you want to use as tunnel to MySQL connection

Authentication Method: ‘Public Key’

Private Key: Path of the private key on your PC

Password: ssh tunnel connection password

If everything has configured correctly when you click to ‘Test Connection’ a confirmation message box will appear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.