linux_wiki:backup_and_restore_a_database

This is an old revision of the document!


Backup And Restore A Database

General Information

Backing up and restoring a database.


Lab Setup

The following virtual machines will be used:

  • server2.example.com (192.168.1.151) → Database installed here

Previous Sections Completed


Backup

Documentation

man mysqldump


Backup 1 specific database: Run the MySQL Dump utility to backup tables within a database

mysqldump -u root -p emails > /backup/emails_backup.sql
  • Builds SQL commands that will create the tables from scratch


Backup multiple databases

mysqldump -u root -p --databases emails mysql > /backup/emails_mysql_backup.sql
  • –databases → flag to backup multiple databases at once


Backup all databases

mysqldump -u root -p --all-databases > /backup/all_dbs.sql

Restore

Restore 1 specific database's tables: Re-create database if it does not exist, then restore the tables

mysql -u root -p
MariaDB [(none)]> CREATE DATABASE emails;
MariaDB [(none)]> quit
mysql -u root -p emails < /backup/emails_backup.sql

  • linux_wiki/backup_and_restore_a_database.1524242203.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)