Remote Database Access
WP Engine provides access to an install’s database via phpMyAdmin in the User Portal. In some cases though, you may prefer an alternate method of running SQL queries against your website. This can be done using SSH Gateway or with a remote database management tool.
SSH Gateway is secure shell access which allows a user to run
wp db query without allowlisting any IPs or using any additional MySQL programs. The
wp db query command is part of the open source WordPress software package, and allows you to run a SQL query against the database information supplied in the
Before you can run a query, you will need to connect to your website’s root directory using SSH Gateway. If you haven’t connected to this feature yet, the step by step process can be found in our SSH Gateway article.
Once you have access to SSH Gateway the process will look like this:
- Connect to SSH Gateway:
- Move to your environment’s root directory:
- Run a database query:
wp db query "your query here;"
- For example, this will list all post titles:
wp db query 'SELECT post_title FROM wp_posts;'
Open MySQL Workbench and create a new connection by clicking on Database → Manage Connections in the menu, then click New.
Give your connection a name and use the following values to configure the connection:
- Connection Method: Standard (TCP/IP) over SSH
- SSH Hostname: environmentname.ssh.wpengine.net (EX: acoolsite.ssh.wpengine.net)
- SSH Username: environmentname
- SSH Password: Leave this blank
- SSH Key File: Use the key file created here
- MySQL Host Name: 127.0.0.1
- MySQL Server Port: 3306
- Username: environmentname
- Password: Use the database password for the website. Found in your
wp-config.phpfile on the line DB_PASSWORD.
- Default Schema: wp_environmentname (EX: wp_acoolsite)
Click Test Connection and you’ll be prompted for the database password you retrieved above. This can be found in
Other Database Management Tools
If you wish to use a different tool to access your database the first step is to start an SSH session with local port forwarding.
ssh -L 3307:127.0.0.1:3306 firstname.lastname@example.org
Now you’ll need to retrieve your MySQL database’s password. Once the connection has been made, enter the following:
grep WPENGINE_SESSION_DB_PASSWORD ./sites/environmentname/_wpeprivate/config.json
Most database management applications require the same pieces of information, just named slightly differently. Here are the standard set of values you’ll likely need:
- Hostname: 127.0.0.1
- Port: 3307
- Username: environmentname (EX:
- Password: Use the database password retrieved above.
- Database: wp_environmentname (EX:
NEXT STEP: Learn about SSH Gateway at WP Engine