WordPress database management automation

The normal functionality of the WordPress database has a crucial effect on the performance of the website. Many users around tend to neglect this topic and usually has serious problems with malfunctioning features or slowly working websites. This article aims to reveal some techniques that would help automate WordPress database management.

For a better understanding of the matter let’s see what is Mysql database: 

WordPress automation

WordPress automation

A database is an optimized, structured and organized set of data. You can think of it as a shelf where you put and get things. WordPress uses such shelf to store information about your content which includes users, posts, pages, images, various descriptions and so on. In order for your WordPress to find the required information faster, this shelf needs to be kept well organized and this requires performing maintenance tasks regularly.  Except for improving the performance, a well-maintained database also reduces the disk space usage and grants better I/O efficiency. 

What are WordPress database management automation options?

WordPress has a great command-line interface tool that supports a number of important database optimization features. The tool can also be used for troubleshooting blank pages as explained here. The commands we will be working today are as follows: 

wp db size --human-readable -> Database size check 

wp db check -> this command provides information about the state of the tables

wp db optimize -> this command checks if optimization is possible and applies it

wp db repair -> this one checks for broken tables 

wp transient delete --expired -> this one deleted the expired transient records

The idea of executing the commands in this order is to avoid problems with larger databases. In the beginning, we check the size. In many cases running queries towards databases over 1GB may result in broken tables and/or overloaded servers. After that, we consecutively run a check, optimize and repair commands. Finally, we delete the expired transient records. The last step is important as sometimes WordPress just does not delete those results and the database gets larger. 

Here is an example of automation based on a shell script that would find your WordPress instance and run the commands in its root folder:

wppath=$(find $PWD -name wp-config.php | sed 's/wp-config.php//g')
echo "List of directories with WordPress apps"
echo "$wppath"
for i in $(echo "$wppath")
cd $i
echo "Working in $i"
dbsizecheck=$(wp db size --human-readable | tail -n1 | awk '{print $2}')
echo "DB size $dbsizecheck MB"
if [[ $dbsizecheck -ge 100 ]]
read -r -p "The database is large. Confirm to continue with the operation [y/N] " response
case "$response" in
wp db check >/dev/nul
wp db optimize >/dev/nul
wp db repair >/dev/nul
wp transient delete --expired >/dev/nul
echo "Opration completed"
echo "Operation aborted"
exit 0
wp db check >/dev/nul
wp db optimize >/dev/nul
wp db repair >/dev/nul
wp transient delete --expired >/dev/nul
echo "Opration completed"
WordPress database management automation
Article Name
WordPress database management automation
WordPress database management automation based on shell script. WordPress command-line interface tool. wp-cli database commands.
Publisher Name

Do you want to share your opinion?

Your email address will not be published. Required fields are marked *


Рязане и пробиване на бетон Сканиране на бетон Безвзривно разрушаване на бетон
We are not industry specific. We are WordPress specific. We work with everyone to help find solutions for the troubles.
If you show us the problem you are experiencing, we will show you how to fix it. It is that simple.

Easy WordPress automation

Switching from human control to automation is an essential step in increasing the efficiency of website development or maintenance. During the past decade, WordPress advanced a lot and became a fully functional Content Management System. Thanks to some of its internal features a large portion of its functionality could be easily automated. The following articles give ideas on how to apply successful automation:

Speed up WordPress

Speed is an important matter when it comes to website success. In order to appear on the first page except for applying the well-known SEO techniques, you will also have to pay special attention to the performance of your website. We have reviewed a number of options and prepared articles for the most important aspects that include database management and dealing with different types of content:

Extend WordPress features

Extending the standard WordPress functionality by building new features was always a hot topic. Developing themes that provide next-level User Experience could also be described similarly. Thanks to the established standards WordPress developers could create standardized extensions that can be downloaded from the official repository. In the following articles, we described some simple techniques that would help start developing your own extensions:

wppotion - powered by persistence and passion