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:

#!/bin/bash
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")
do
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 ]]
then
read -r -p "The database is large. Confirm to continue with the operation [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
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
;;
esac
else
wp db check >/dev/nul
wp db optimize >/dev/nul
wp db repair >/dev/nul
wp transient delete --expired >/dev/nul
echo "Opration completed"
fi
done
Summary
WordPress database management automation
Article Name
WordPress database management automation
Description
WordPress database management automation based on shell script. WordPress command-line interface tool. wp-cli database commands.
Author
Publisher Name
WPpotion


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 them find solutions with their troubles.
If you show us the problem you are experiencing, we will show you how to fix it. It is that simple.


Reported WordPress issues

  1. Wordpress: How to create a website that customer can make their own profile in there and observable via their pages
  2. How do I make my SVG larger within a HTML table?
  3. Replace result of a wordpress function in a hook
  4. i receive this email from my data center :“ We have detected abuse…”
  5. Is it wordpress plugin [on hold]
  6. After AWS Cloudfront Setup Browser Info is Incorrect
  7. wp mail smtp settings takes in custom created plugin
  8. Exclude page from restriction
  9. WP All-in-One Migration shows “wp-config already exists”
  10. contact form 7 wordpress dropdown

WordPress problems we are working on

  1. Wordpress multisite redirects subpages to homepage
  2. Programmatically add value to custom field based on custom field
  3. Failed to load resource: the server responded with a status of 503 ()
  4. How to find relavant element from an array based on index using number in the loop?
  5. Wordpress custom Gutenberg Block not reloading correctly
  6. Suddenly starts receiving alert when trying to login to wordpress admin panel
  7. Issue with polish character in FPDF
  8. How to fix theme thumbnails without uploading images to media library?
  9. Highlighting Current Page in Nav_Menu (WordPress) /w SASS
  10. API integration in WordPress to pass login details to app

Resolved issues

  1. How To Allow Special Characters & Capital Letters In Wp Permalink?
  2. Create Submenu with Redux Framework _WordPress
  3. Wordpress Boostrap NavMenu on mobile hides after displaying
  4. Can give access to only one Plugin?
  5. Youtube within a Paywall site
  6. How To Add Custom Fields in Dokan Vendor Dashboard
  7. How to extract Product attributes from Product Variations
  8. Stripe Payment Button Not Responsive
  9. Output ACF Flexible Content fields in a table (with the table header not to be repeated through loop)
  10. How do I create a sliding team section with variable positioning and z-indexes?
wppotion - powered by persistence and passion