October 15, 2019

Backup and Restore MySQL or MariaDB Database on Linux Server

Check the database name by login to the MySQL Server following the command below

# mysql -u root -p

Then type the following command inorder to check the database table

mysql> show databases;

Mysqldump command is used for taking the mysql backup

# mysqldump -u root -p db_name > /backup/db_name.sql

For example:- to backup the testdb, use the command as follows

# mysqldump -u root -p testdb > /backup/testdb.sql  (This command is used to backup a single database).

Entire database backup command:-

# mysqldump -u root -p –all-databases > /backup/all_db.sql

Single table backup

mysql -u root -p database name table name > databasename_tablename.sql

For example:-

  # mysqldump -u root -p testdb accounts >testdb_accounts.sql

To restore MySQL database?

In order to restore the database backup, we have to use the command: mysql -u root -p  db_name < /backup/db_name.sql

TYpe the command:-

# mysql -u root -p testdb < /backup/testdb.sql  //this is just a example

Vedant Singh

Linux System Administrator | Entrepreneur | Founder Techmion. I have started my career as a Linux system Administrator after that quit my job to start something new that excites me and started a Tech Company in order to provide the best technology to my clients. My Company website link: Technology at its best For Bulk, SMS-Marketing follows the link : https://www.pingsms.in/

View all posts by Vedant Singh →

Leave a Reply

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