Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

Database Backups

Topics covered

 Backing up by directly copying files.


 Using mysqldump and mysqlhotcopy.
 The BACKUP and RESTORE command.
What is Database backup

 A backup is a copy of data from your database that can be used to reconstruct that
data. Backups can be divided into physical backups and logical backups.
 Physical backups are backups of the physical files used in storing and recovering
your database, such as datafiles, control files, and archived redo logs. Ultimately,
every physical backup is a copy of files storing database information to some
other location, whether on disk or some offline storage such as tape.
 Logical backups contain logical data (for example, tables or stored procedures)
exported from a database with an Oracle export utility and stored in a binary file,
for later re-importing into a database using the corresponding Oracle import
utility.
Why do we need to backup database

 Data loss can happen in many ways, the most common causes are physical failure
of your PC, accidental error, theft or disasters like fire, flood and dropped coffee
mugs! It is also common for data to be saved to just one place, like ‘My
Documents’ on your PC’s hard drive. Which means that if this data were to be
accidentally changed or deleted it would take considerable time and expense to
restore it.
Using mysqldump and
mysqlhotcopy
1. Find the Program Data folder on your computer. It is hidden in your C:/ . Or if your Program
Data is not hidden, you can go to this directory ( C:\ProgramData\MySQL\MySQL Server 5.1\data ).
Now you can see all your database. You can backup it by copying the folder on your flash drives
and bring it back whenever something bad happens.
Mysqldump

 The mysqldump client utility performs logical backups, producing a set of SQL


statements that can be executed to reproduce the original database object
definitions and table data. It dumps one or more MySQL databases for backup or
transfer to another SQL server. The mysqldump command can also generate
output in CSV, other delimited text, or XML format.
Mysqldump (backup)
 Open up a Windows command prompt.
 Click Start -> Run
 Enter “cmd” into the dialog box and click the “OK” button.
 Change the directory to the following to access the mysqldump utility.
 cd C:\Program Files\MySQL\MySQL Server 5.5\bin
 Create a dump of your current mysql database or table (do not include the bracket symbols [ ] in your
commands).
A database dump (also: SQL dump) contains a record of the table structure and/or the data from
a database and is usually in the form of a list of SQL statements
 Run the mysqldump.exe program using the following arguments:
 mysqldump.exe –u[username] -p[password] -h[hostname] [database name] > C:\[filename].sql
Mysqldump (restore)

 Open up a windows command prompt.


 Click Start -> Run
 Enter “cmd” into the dialog box and click the “OK” button.
 Go to the directory that the mysql client utility is located.
 cd C:\Program Files\MySQL\MySQL Server 5.5\bin
 Import the dump of your database or table.
 Run the mysql.exe program using the following arguments.
 mysql –u[user name] -p[password] -h[hostname] [database name] < C:\[filename].sql
The BACKUP and RESTORE command.
Backup

 How to back up multiple databases


- mysqldump.exe –u[username] -p[password] --databases [database name] [database name]  >
C:\[filename].sql

 How to back up all databases


- mysqldump.exe –u[username] -p[password] --all-databases  > C:\[filename].sql

 How to Backup MySQL Database Structure Only


- mysqldump.exe –e –u[username] -p[password]  --no-data [database name]  > C:\[filename].sql
Backup
 How to Backup MySQL Database Data Only
 mysqldump.exe –u[username] -p[password] - -no-create-db - -no-create-info [database
name]  > C:\[filename].sql
 How to Backup Single Table of Database
 mysqldump.exe –u[username] -p[password] [database name] [table name]  > C:\
[filename].sql
 How to Backup Multiple Tables of Database
 mysqldump.exe –u[username] -p[password] [database name] [table name] [table
name]  > C:\[filename].sql
Structures only

Single and multiple table


RESTORE

Syntax
 mysql –u[user name] -p[password]  [database name] < C:\[filename].sql
Restore multiple databases
mysql –u[user name] –p[password] [database name1]_ [database name2] < C:\
[filename].sql
Restore all databases
mysql –u[user name] –p[password] --databases [database name1]_ [database name2]
< C:\[filename].sql
Single database

Multiple databases

All databases

You might also like