MySQL is a Relational Database Management System (RDBMS). It handles database instructions and can manage many databases at the same time.

For example, if you want to create a new database or add data to an existing database, you send a message to the MySQL server, give it the data you want to add, and tell it where to add it.

Table of Contents
    How To Backup a MySQL Database image 1

    Whether your business is small or large, your data is an essential element. To ensure that your valuable information is secure from damage, theft, or the effects of a disaster, backup your MySQL database. This article will explain several ways to do that.

    Backup MySQL Database Using phpMyAdmin

    Create an export or backup file of your MySQL database by accessing the phpMyAdmin tool from your web hosting control panel such as cPanel. We will use cPanel for the purposes of this article.

    • Start by logging into your cPanel and clicking on phpMyAdmin.
    How To Backup a MySQL Database image 2
    • Choose the MySQL database you want to back up from the navigation panel on the left sidebar. Then click the export link located on the top navigation bar.
    How To Backup a MySQL Database image 3
    • From the Export page, you will see two options: Custom and Quick. Select the Custom option.
    How To Backup a MySQL Database image 4
    • After choosing Custom, you will see a list of your databases. You can select one, some, or all. The default setting is to backup all.
    • Under the Output options, choose gzipped for Compression. Leave the other options as the defaults.
    How To Backup a MySQL Database image 5
    • Click the Go button to start the backup and download your file. The name of your file will be YourDatabaseName.sql.gz file.

    The time it takes for the backup to complete will depend upon the size of your database.

    Backup MySQL Database With mysqldump

    Use the mysqldump command to create a text file dump of your database that will be managed by MySQL. A text file dump is a text file that includes the SQL commands you need to recreate your database from scratch.

    • To back up a single database, use the following command:

    mysqldump database_name > database_name.sql

    This command will create the backup and send it to a .sql file. It will only make a copy of your database and won’t affect it.

    • Use the following command to backup multiple databases at the same time.

    mysqldump –databases database_one database_two > two_databases.sql

    Database_one refers to the name of the first database and database_two is the name of the second database you want to back up. Both will be backed up into a single database.

    • If you want to backup all your MySQL databases on a server, use the following command to create a single .sql backup file that will contain all your databases.

    mysqldump –all-databases > all_databases.sql

    Backup MySQL Database Using Cron Jobs

    A cron job is a Linux command used to execute a task at a specified time automatically. We will explain how to use this command to automate a backup of MySQL databases. 

    • Start by logging into your cPanel and scrolling down to the Advanced section and click on Cron jobs.
    How To Backup a MySQL Database image 6
    • You will see a warning that you should have a good knowledge of Linux commands to use cron jobs effectively. If you don’t, check with your hosting administrator.
    How To Backup a MySQL Database image 7
    • If you want to receive an email every time a cron job runs a command that produces output, put your email address in the box and click Update Email.
    How To Backup a MySQL Database image 8
    • Choose one of the Common Settings from the dropdown menu to select how often you want to run the backup.
    How To Backup a MySQL Database image 9
    • You can also tweak the other settings such as time and day of the week.
    How To Backup a MySQL Database image 10
    • Now it’s time to put in the command as follows:

    /usr/bin/mysqldump -u dbusername -p’dbpassword’ dbname > /home/username/path/backup.sql

    How To Backup a MySQL Database image 11
    • Replace dbusername, dbpassword, and dbname with your database username, database password, and database name.
    • Path refers to a folder or series of folders where you want your backup file to go. The name of your backup file is represented in the command as backup.sql. You can change that name or leave it as is. Click Add New Cron Job.
    • If you scroll down a little bit, you will see a list of your Current Cron Jobs.
    How To Backup a MySQL Database image 12
    • If you want to change any of your current cron jobs, click Edit. If you no longer want to run any job or make a mistake, click Delete.

    Use WordPress (WP) Plugins to Backup MySQL

    If you are using WP, you can use a plugin to back up your database. UpdraftPlus will back up your database file with a single click. It currently has over two million active installs.

    How To Backup a MySQL Database image 13

    BackWPup

    Use BackWPup to backup your MySQL database files and even your complete WP installation.

    How To Backup a MySQL Database image 14

    There are many more WP plugins available to back up MySQL. Choose one that works with the current version of WP and is being actively updated.

    To avoid losing critical data, regularly backup your MySQL database. If you have a backup, you will be able to restore essential or irreplaceable data should something happen to corrupt your site.

    Leave a Reply

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