Remote Database Access
WP Engine provides access to an install’s database via phpMyAdmin in the User Portal, instead of offering cPanel. In some cases though, an alternate method of running SQL queries remotely on a website’s database may be preferred. The database can be access remotely with SSH Gateway, or with a remote database management tool that supports SSH connections.
SSH Gateway
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 the running of a SQL query against the database information supplied in the wp-config.php file.1
With this connection method you do not need to retrieve your database username and password, as you will be connecting to a secured tunnel specific to your user.
Learn more about wp db query here.
Before a query can be run, connect to the website’s root directory using SSH Gateway. The step-by-step process for new connections can be found in the SSH Gateway article.
Running a query on SSH Gateway will look like this:
- Connect to SSH Gateway:
ssh environmentname@environmentname.ssh.wpengine.net
- Move to the environment’s root directory:
cd sites/environmentname
- Run a database query:
wp db query "some query here;"- For example, this will list all post titles:
wp db query 'SELECT post_title FROM wp_posts;'