December 21, 2024

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 Kumar

Currently I'm working as an Implementation Engineer, Started my career as an System Administrator - Linux. Additionally loves to explore new technologies and research about new open-source software that ease the development cycle.

View all posts by Vedant Kumar →

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.

close

Ad Blocker Detected!

VEDANT EXPLAINS
We've noticed that you are using an ad blocker. Advertising helps fund our server cost and keep it truly independent. It helps to build our content creator team. So please disable your ad blocker, and help us to keep providing you with free- great content - for free. Thank you for your support.

Refresh