In the course of managing your website, there may come a time when you must run a query against your WordPress database. At WP Engine, the easiest way to do this is via the phpMyAdmin tool, found in your User Portal. In this article we will explain how to access phpMyAdmin, and how to run queries against your WordPress website’s database.
WordPress and Your Database
WordPress is a PHP-based Content Management System. In PHP, when requests come to your website pages, these pages don’t exist as static files like they do with HTML. The server instead has to build your page. PHP code triggers MySQL queries to your site’s database to get information like: page and post content, settings, user permissions, and much more. When you edit a page’s content in the WordPress Admin Dashboard, those changes are pushed to your site’s database and are stored there for your site to access the next time that page is requested.
With that in mind, there may be times where you need to get an export of specific types of content on your database that the WordPress Admin Dashboard doesn’t directly provide. Or, you might need to optimize your database so that your page content shows faster for your users. All of these things can be accomplished using phpMyAdmin, which is the web interface to interact with your database.
Accessing phpMyAdmin
Your first step in running a query manually is to access phpMyAdmin. WP Engine makes this part pretty simple. First, navigate to the environment where you need to make changes or export data in your User Portal. In the left-hand navigation, select “phpMyAdmin.”
You will be taken to a phpMyAdmin window which shows either one or two databases: wp_environment and optionally, snapshot_environment. If you have a snapshot_environment database, this relates to your one-click staging environment which you use from the WordPress Admin Dashboard. The wp_environment database (present for all sites) relates to the standard environment and is usually the one you will want to access. Select the database for the environment you wish to use to get started.
Once you select your database, you will see a list of database tables like: wp_posts, wp_users, and wp_options.
Generally speaking, your list of users and their email addresses can be found in wp_users, while their permissions are managed in wp_usermeta. And your posts, pages, and media can all be found in wp_posts, while metadata like templates, SEO scores, and other data from plugins will usually be found in wp_postmeta. And last, wp_options will hold information and settings for your website such as active plugins, active theme, and your site’s primary domain.
Run a query
Now that you have navigated to your database and seen your list of tables, you should have a general idea of which table(s) from which you need to gather or update information. In order to run a query, you will need to use the MySQL language. Learn more about MySQL queries.
Once you know what query you need to run, click the MySQL tab at the top of phpMyAdmin.
Enter the query, and hit “Go” to execute the query. Be aware: If you are running UPDATE or INSERT queries, these will change or add data to your database. You should make a backup in User Portal before doing this to be safe.