Home MySQL How to Backup WordPress Database via MySQL

How to Backup WordPress Database via MySQL

As a Linux system administrator, various operating system responsibilities demand that you should always be a few steps ahead in terms of your administrative prowess.

One of them is ensuring your WordPress site’s user-related and system-related database backups are scheduled and made on time. There are several reasons why you need to schedule and make several database backup copies. One of them is data security and the other one is data integrity.

Data security protects system users from losing their cumulative site information because of circumstances related to bugs in the website’s source code, server hardware failures, and even programming errors.

On the other hand, data integrity is a coping mechanism from hackers that may have illegally accessed your WordPress site and changed some information or tried to extract sensitive user and system data.

Backing Up Your WordPress Database via MySQL

To successfully backup your WordPress database, you need to familiarize yourself with a special SQL command called mysqldump. This command, (mysql+dump), makes use of other associated MySQL database commands syntax to generate text dumps of the targeted user or system database records. The resulting SQL dumps can be used to re-generate an original copy of the already existing WordPress database.

mysqldump Command Syntax

From the below command syntax, you can give dump_file_name.sql any name you like as it will be regenerated each time you re-run another mysqldump command instance to create a new MySQL database backup file.

$ mysqldump -u [your_username] -p [your_database_name] > [dump_file_name.sql]

In this article, we are going to look at three approaches to MySQL database backup using the mysqldump command:

  1. Backing Up a Single MySQL Database Record.
  2. Backing Up Multiple MySQL Databases Records.
  3. Backing Up All MySQL Databases Records.

Identifying MySQL Database(s) to Backup

Log in to the MySQL command-line as root database user.

$ mysql -u root -p 

Display all the available databases so that it would be easier to identify the ones whose records your backup.

MariaDB [(none)]> SHOW databases;
List WordPress Database
List WordPress Database

From the above screen capture, there are five existing MySQL databases. Let us now work on achieving the three mentioned MySQL database backup approaches. First, create a backup directory that will be hosting your generated WordPress database copies:

$ mkdir WordPress_DB_BackUps 
$ cd WordPress_DB_BackUps

Backing Up WordPress Database

In reference to the mysqldump command syntax, we need to specify the database user, the database password, the targeted database name, and the name of the .sql extension file where the generated WordPress database copy will reside.

In this case, let us try to backup the wordpress database.

$ mysqldump -u root -p wordpress > wordpress_db_backup.sql

Confirm that the database backup file was generated.

$ cat wordpress_db_backup.sql
Check WordPress Database
Check WordPress Database

Backing Up Multiple MySQL Databases

Let us try to backup both wordpress and lst_db databases.

$ mysqldump -u root -p --databases wordpress lst_db > wordpress_and_lst_db_backup.sql

Confirm that the two databases’ backup file was generated.

$ cat wordpress_and_lst_db_backup.sql
View Database Contents
View Database Contents

Backing Up All MySQL Databases

Let us try to backup all the databases.

$ mysqldump -u root -p --all-databases  > all_db_backups.sql

Confirm all databases backup file was generated.

$ cat all_db_backups.sql
View All Database Contents
View All Database Contents

When it comes to backing up a MySQL database, you can choose to back up a single database, multiple databases, or all databases. The MySQL CLI power is in your hands now.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.