Backup and Restore MySQL or MariaDB Database on Linux Server

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

Backups MariaDB MySQL Databasesmysql export database command linemysqldump all databasesmysqldump multiple databasesmysqldump table
Comments (0)
Add Comment