WordPress

[WordPress on VPS] How To Backup and Restore MySQL Database

 

The database is the backbone to all WordPress websites, which is why knowing how to back up and restore MySQL database is a crucial step to getting prepared when needed.

Here is how you can do it and do it all from the shell command line without the popular phpMyAdmin.

Backup MySQL Database

mysqldump is the command line we will be using to backup MySQL database data. Basically, it reads the data from the database and writes them to a dump file with all the SQL commands needed to re-create the database from scratch.

To backup a single database, use

$> mysqldump -u root -p db-name > db-backup.sql
Enter password:

Type in MySQL’s root password and it’s done.

You can also backup multiple databases by use the –databases switch.

$> mysqldump -u root -p --databases db1,db2,db3 > db-backups.sql

Or, simply use the –all-databases to backup all databases you have loaded in your MySQL.

$> mysqldump -u root -p --all-databases > db-all-backup.sql

If your database is very big, it’s a good idea backing up the database with compression. Just pipe the output to the gzip command line and you will get the compressed backup copy in gzip format.

$> mysqldump -u root -p db-name | gzip -9 db-backup.sql.gz

Restore MySQL Database

Since the backup file is full of SQL commands, we can restore databases by simply telling mysql command to run the commands in the backup file and put the data into the proper database.

If the backup file is only for a single database, use

$> mysql -u root -p db-name < db-backup.sql

If the backup file contains multiple databases, here is how to use it to restore to a specific database.

$> mysql -u root - p --one-database db-name < db-all-backup.sql
edge

Share
Published by
edge

Recent Posts

Disable Copilot on Windows 11 via Group Policy GPO

If using Copilot right from the Taskbar isn't your thing, you should disable it. Even…

7 months ago

Setting Default Fonts in Word, Excel, Outlook, and PowerPoint via Group Policy

In an environment where standardizing things does matter, setting default fonts in Microsoft Office apps…

8 months ago

Wake-On-LAN (WOL) with Windows and PowerShell

Wake-On-LAN is a networking standard that lets you wake up a computer from either a…

8 months ago

How To Remove Restrictions Set in A Password-Protected PDF File

First of all, this is not to bypass a PDF file that requires a password…

8 months ago

How To Move My Outlook Navigation Bar Back From Left Back To the Bottom

Microsoft has been lurking about the idea of placing the Outlook navigation bar to the…

2 years ago

Headset with Microphone Echoing My Own Voice on Windows, What To Do?

One colleague came up to me the other day asking me to take look at…

2 years ago