WordPress, now the number one CMS platform across the globe, is made by using PHP as the scripting language and MySQL database. However, to use WordPress for web development, you don’t really have to know PHP or MySQL, but a basic understanding of both will surely help you in managing WordPress themes and also to troubleshoot the database issues.
In this excerpt, we will discuss how WordPress uses the databases to change themes and a variety of other purposes. Here, we use the tool phpMyAdmin to manipulate WordPress database and will go through an actionable insight about creating database backups, changing themes using database, and optimizing WordPress database etc.
As discussed above, PHP is the programming language that WordPress uses to store and recall data from the backend MySQL database. WordPress database consists of pages, posts, custom fields, categories, comments, users, tags, site URLs etc. On first installation of WordPress, you may be asked to provide information like name of database, host name, username, and a password. All this information gets stored in a configuration file i.e. wp-config.php.
During installation, WordPress will use the information provided by you and insert data by default into the database tables. After installation, WordPress will start running queries to the database and dynamically generate the HTML pages for the new website. This makes WordPress the most user-friendly platform in web development as users need not have to create new.html files each time to create a page.
Eleven default tables are created with every WordPress installation. Each of these consists of data for various features and functionalities. When you look at the structure of these tables, you can easily understand where the various parts of a WordPress website get stored. Let’s see below the default WordPress tables.
Containing the meta data about the comments posted on a WordPress web page. There are four fields in this table such as:
This is a table meant to contain the WordPress comments. It contains comments like URL, author name, e-mail, comments etc.
It stores the blog links created by the Link manager plug-in or previous versions of WordPress.
To store the settings as:
A table holding meta information about various posts and pages. It stores details of the templates to display pages and custom fields etc. Some WordPress plug-ins may also access this table to store the plugin data like WordPress SEO info.
This table consists of all the post types or content types including all pages, posts, revisions, and the custom post types.
WordPress features an efficient taxonomy system to well organize the user content. These taxonomy items are known as terms which are stored in wp_terms table.
Table that manages relationship of WordPress posts with the terms in the previous table. This table helps WordPress to know that post B is under the A category.
Table defines taxonomies for the terms in wp_terms table. Table consists of data which helps WordPress to differentiate between category and tag etc.
This table consists of meta data about users of the website.
With user info as:
For WordPress developers, phpMyAdmin is a highly user-friendly interface for database support and manipulations. phpMyAdmin is installed by default into the control panel of many hosting panels. To access the phpMyAdmin in C-panel, just click on the phpMyAdmin at the scroll down. This will open in a new tab.
Clicking on it will show you a list of databases as above created during WordPress installation. Clicking on each WordPress database will further open the list of WordPress database tables. On accessing it, you can perform various tasks through phpMyAdmin interface such as changing WordPress theme, edit or replace content of posts, do database repair, database optimization, adding user and admin, activate or deactivate plug-ins, changing passwords etc.
*IMP: Before making any changes, always create backup of the database. To do this from phpMyAdmin, click on WordPress Database and click the Export tab on the menu.
Step #1 - Open Database in the phpMyAdmin
Step #2 - Click wp_options table on the left-hand side to open the table. Note that the prefix ‘wp_’ may be different is some cases. If you have multiple WordPress installation using 1-click installer or so, the prefix may be usually ‘0_’ or so.
Step #3 - In the table, locate the adequate theme. Also check the rows named template / stylesheet to change these. It is usually found on the second page of the options table.
Step #4 - Replace theme. Click on the field ‘option_value’ to replace the theme and press enter to save. The same thing can be done for template and stylesheet.
Theme is now changed and you can access your website again by logging in to WordPress dashboard and see the change.
The optimization feature through phpMyAdmin can be used to optimize the WordPress tables by defragmenting the tables. This can help reduce the size of the database and make the queries run faster. You can also reset the WordPress password, add an admin or user to WordPress database through MySQL, change WordPress username, and deactivate all the WordPress Plugins also from phpMyAdmin.
You can try all these database creation, manipulation, theme change, or deactivation of plug-ins all by yourself, but before doing so, you need to be aware of the possibility of your site getting hacked. It is essential to focus on security, for which the first step you can take is to change the database prefix. Also choose a very strong username and password for your database. This will make it difficult for the intruders to crack it. Hope this guide helped to understand the basics of WordPress database and how it works in terms of theme change and other basic functionality.
Author's Bio: Sujain Thomas is a web development specialist and a freelance IT consultant. She keeps on publishing many articles on a wide range of poplar blogs on user-friendly CMS based web development methods, database connectivity, database support, website security etc.