Prestashop logo, Visit home page

Database connection

-

There are three ways to connect to each environment's database: you can use PhpMyAdmin or a database explorer configured with remote connection, or you can also use the mysql command line while connected with SSH to your environment.

 

PhpMyAdmin

Logging in to PhpMyAdmin is very easy. On the Credentials page for each environment, scroll down to the Database section. There is a button that will take you directly to the PhpMyAdmin interface. Make sure to copy the username and password to the clipboard as you will be asked to enter these details.

Hosting_databaseconnection.png

Hosting_phpmyadmin.png

 

Remote Connection

When PhpMyAdmin isn't enough, it's always possible to connect your own database explorer to your PS Platform-powered database. There are many tools available these days, including MySQL Workbench, Navicat, Datagrip, ... We will use DataGrip to document how to configure your connection, but the principle will be the same in all database tools.

You will log in with the database user "admin" which has full access to this database. Be careful when executing delete or update statements when not logged in in read-only mode.

 

SSH Tunnel

For security reasons, the database port will not be made public. This configuration is therefore a little more complex. First, make sure the SSH key has been added to your account and SFTP is enabled (regardless of general Git/SFTP mode). Now that the SSH keys have been added and the SFTP port is open, a tunnel to the MySQL port can be configured.

 

Command line

To create an SSH tunnel to the MySQL port, copy this command to the clipboard and run it in your local shell. The command will have the following format:

ssh -L 13306:127.0.0.1:3306 -N [SFTP_USERNAME]@[SFTP_HOSTNAME] -p [SFTP_PORT]

You can now connect to your MySQL instance on port 13306 and host 127.0.0.1.

 

Database Explorer

When adding a new data source in our tool, DataGrip, navigate to the second tab called SSH/Tunnel. The fields to enter here can be found in the Credentials tab under SFTP. There you will find the fields HostPort et Username. Authentication will always be done with your private key.

Hosting_sftpaccess.png

Now that all settings are available, enter them into your data source configuration.

Hosting_sshtunnel.png

Database connection

Now that the tunnel is configured, connect to your database as you would a database on your local machine. Make sure to use 127.0.0.1 for your host and NOTlocalhost ! Port forwarding will not be available onlocalhost. The database username and password can be found under the section Database of your identifiers, just like those used for PhpMyAdmin.

When a tunnel has been established using the command line method, be sure to connect to the configured local port. (`13306`in this case)

Hosting_database.png

 

MySQL Command Line

Finally, you can access your database with the mysql command line while connected with SSH to your environment.

First, you will need to navigate to the Credentials tab of PS Platform to obtain the necessary user and password.

Then you can log in with the following command:

mysql -u <USER> -p<PASSWORD> <DB_NAME>

Note: no need to indicate the host, localhost will be used by default.

Share

Was the article helpful?