SQL Queries in phpMyAdmin

At WP Engine, the easiest way to access and work with your database is through a tool called phpMyAdmin. phpMyAdmin makes it easy to securely view and edit data as well as run queries to update data in bulk. If you are looking to optimize your WordPress website, you will likely need to perform several actions in phpMyAdmin.

NOTE

Want to access your database a different way? Try SSH Gateway instead.


Access Database with phpMyAdmin

To easily view your website’s database with phpMyAdmin in the WP Engine User Portal:

  1. From the Sites page, select the environment name
  2. Click phpMyAdmin at the top right
  1. A new tab will open and you will see the phpMyAdmin interface load
  2. Click on the database name in the far left column
    • wp_environmentname — The primary database for this environment

Run Query in phpMyAdmin

  1. Open phpMyAdmin
  2. Select the database you’d like to run a query on
    • You must select a database from the left column first
  3. Select SQL
  4. Look for the database name again above the text field, confirm this is the correct database you intend to run a query on
  5. Write or paste your query in the text field
  6. Click GO
    • Some queries will require a second confirmation in order to run.

NOTE

If running UPDATE or INSERT queries, these will change or add data to your database. Make a backup beforehand.


Custom Database Prefix

Queries must be run in SQL and will most likely reference specific table names. Tables will not always be named the same thing from site to site, however.

Database prefixes can be changed for security reasons and may have been done so by a previous host if you migrated the site. Changing your database prefix means all of your tables are titled something new and are not using default titles. A custom prefix can be any string of random characters.

If you are running a query you must ensure you are taking into account if a custom database prefix is being used in order to properly run a query.

The default WordPress database prefix is wp_ and default tables are titled like this:

In this example, there is a custom prefix of wp_zgs0q4pna9_ and the table names look like this:

In this example, there is a custom prefix of test_ and the table names look like this:


Find the Database Prefix

If you cannot clearly distinguish your table names and prefix just from looking at your tables, you will need extra steps to locate which prefix (and subsequently, which tables) you are active.

  1. Connect to your site’s filesystem using SFTP
  2. Download the file wp-config.php from the root directory
  3. Open this file and locate the line $table_prefix
  4. Your database prefix will be within the quotes
    • In this example the prefix is wp_zgs0q4pna9_

If you need to change your database prefix, check out our guide.

NOTE

It is recommended but not required that your database prefix include a trailing underscore at the end, however it is not required.


Run SQL Query with a Custom Database Prefix

You’ve found a SQL query you want to run but you’ve discovered you have a custom database prefix so the command doesn’t work correctly. You’ll need to slightly modify the SQL query to work on your site.

Wherever you see wp_ in a SQL query, just replace it with your prefix. This may be more than one location if the query interacts with multiple tables.

Example

For this example, we use the prefix: wp_zgs0q4pna9_

Default query example:

SELECT SUM(LENGTH(option_value)) FROM wp_options WHERE autoload = 'yes';

This command targets the table wp_options but we need it to target the wp_zgs0q4pna9_options table. Replace wp_ with your custom prefix for the command appropriate for this site.

Customized query:

SELECT SUM(LENGTH(option_value)) FROM wp_zgs0q4pna9_options WHERE autoload = 'yes';

NOTE

We’ve used an example database prefix. Yours will be different and will need to be modified appropriately.


NEXT STEP: Setup Remote Database Access

Still need help? Contact support!

We offer support 24 hours a day, 7 days a week, 365 days a year. Log in to your account to get expert one-on-one help.

The best in WordPress hosting.

See why more customers prefer WP Engine over the competition.