MySQL is the database management system used by WordPress to store and retrieve your blog information. It acts as a filing cabinet for your website and is pronounced ‘my sequel’.
While you can use WordPress without knowing how to use MySQL, a basic understanding can help you troubleshoot problems with your WordPress site.
What Is a Database?
Think of it as a digital filing cabinet that organizes and stores all of the data on your website.
Information is retrieved, added, and deleted from tables in the database using a special programming language called SQL, or Structured Query Language. A SQL instruction to retrieve data is known as a query.
A typical MySQL query looks like this:
SELECT * FROM wp_posts WHERE ID = 23;
You don’t need to understand how databases work or learn the SQL language to use WordPress. All of this happens automatically behind the scenes. However, a knowledge of MySQL can help with troubleshooting.
You can fix many WordPress errors by working directly with the database, especially when you’re unable to log in to the WordPress admin area. For example, you can reset a WordPress password, add an admin user, and change the WordPress email address.
You can access your MySQL database using phpMyAdmin. This is a web application that lets you manage MySQL databases using a web browser. You’ll find it in your web hosting provider’s control panel.
To learn more about databases and how to use them, see our beginners guide on WordPress database management with phpMyAdmin.
How Does WordPress Use MySQL?
WordPress stores a great deal of information in a database, including posts, pages, comments, categories, tags, custom fields, users, and other WordPress settings.
That’s why, when you first install WordPress, it asks you to provide a database name, host, username, and password.
This information is stored in the configuration file called wp-config.php.
During the installation, WordPress uses the information you provide about the database to create tables and store default installation data inside those tables.
Each WordPress installation starts with 12 default tables in the database. These contain data for different sections, features, and functionality of WordPress.
Currently, a default WordPress installation creates the following tables:
wp_commentmetacontains meta information about comments
wp_commentscontains comments and the comment author’s details
wp_linksmanages blogrolls created by earlier versions of WordPress
wp_optionscontains most of the site wide WordPress settings
wp_postmetacontains meta information about posts, pages, and custom post types
wp_postscontains your posts, pages, custom post types, and revisions
wp_termmetacontains metadata for terms under custom taxonomies
wp_termscontains terms under taxonomies, such as each category and tag
wp_term_relationshipsmanages the relationships between post types and terms
wp_term_taxonomydefines taxonomies to differentiate between categories and tags
wp_usermetacontains meta information about registered users
wp_userscontains user information including usernames and passwords
wp_ before each table name is the default database prefix. You might like to choose a different prefix during the WordPress installation to improve the security of your website.
Because your WordPress content is stored in MySQL, your website backup solution will need to make a copy of your database tables as well as the files stored in your media library, themes and plugins.
Backup plugins such as UpdraftPlus will automatically send complete backups of your WordPress files and database to a remote location. You can learn how to set it up by following our guide on how to backup and restore your WordPress site with UpdraftPlus.
How MySQL Affects Website Performance
MySQL runs on your web server as an application, so requires more resources when more users visit your website. That’s because each time a user visits your website, WordPress has to fetch the information from the database before the web page is sent to the user’s browser.
This makes your website load slower when a lot of users are visiting it at the same time.
Most websites address this by using a WordPress caching plugin. These plugins store frequently requested web pages so that your database doesn’t have to be queried as often. As a result, your website runs faster.
You can follow our guide on how to install and set up WP Super Cache on your WordPress site to see how easy it is to add a caching solution to your website.
Running MySQL on Your Computer
If you wish to run WordPress locally on your computer, then you will need to run the same software as your WordPress hosting provider. This includes Apache (the webserver software), MySQL (the database) and PHP (the programming language).
We hope this article helped you learn more about MySQL in WordPress. You may also want to see our Additional Reading list below for related articles on useful WordPress tips, tricks, and ideas.
- How to Reset a WordPress Password from phpMyAdmin
- Beginner’s Guide to WordPress Database Management with phpMyAdmin
- How to Add an Admin User to the WordPress Database via MySQL
- How WordPress Actually Works Behind the Scenes (Infographic)
- 50 Most Common WordPress Errors and How to Fix Them
- How to Change the WordPress Admin Email (3 Methods)