• Recent blogs

    How to Take Backup Of MySQL/MariaDB Database and Restore it

    How to Take Backup Of MySQL/MariaDB Database and Restore it..

    Backup of MySQL database with the native tools is something that most the MySQL admin does. I'll take you through the backup procedure of MySQL DB using mysqldump command. This procedure works  across all the Linux distribution.


    You need a MySQLsql instance up and running. Need Privileges on that database you are trying to backup or root user password with you.


    1. Take backup of a Single database on a Linux Server?
    All the backing up will done by the "mysqldump" command. In this example we'll be taking backup of DB "exampledb1 " and the backup will be stored at "/tmp/exampledb1_exampleserver1.sql" .

    mysqldump -u root -ppassword exampledb1 > /tmp/exampledb1_exampleserver1.sql

    2. Take Backup of all databases on a Linux Server?
    Just in case you have multple DB instances on same server, you can take backup of them "--all-databases" switch in mysqldump.
    mysqldump -u root -ppassword --all-databases > /tmp/all-database_exampleserver1.sql

    3. How to Compress the Backup.
    To save space you can compress the backup using -C option.
    mysqldump -u root -ppassword -C exampledb1 > /tmp/exampledb1_exampleserver1.sql.tgz


    In case there is a need arise to restore the Database or to act in a drill. Please follow the procedure given below.

    1. On the Machine where you want to restore, First create the related Databases?
    mysql -u root -p
    on the mysql prompt,
    MariaDB [(none)]> create database exampledb1;   --> Database exampledb1 is created now
    MariaDB [(none)]> exit

    2. Now Restore single Database on a Linux Server.
    mysqldump -u root -ppassword exampledb1 < /tmp/exampledb1_exampleserver1.sql

    3.  Now restore All Databases on a Linux Server:
     mysqldump -u root -ppassword --all-databases < /tmp/all-database_exampleserver1.sql

    To Know For More Info on MariaDB Backup/Restore, Please follow this link.

    No comments