物理备份
物理备份又分为冷备份和热备份。
Physical backups consist of raw copies of the directories and files that store database contents. This type of backup is suitable for large, important databases that need to be recovered quickly when problems occur.
Logical backups save information represented as logical database structure (CREATE DATABASE, CREATE TABLEstatements) and content (INSERTstatements or delimited-text files). This type of backup is suitable for smaller amounts of data where you might edit the data values or table structure, or recreate the data on a different machine architecture
一 冷备份
冷备份就是停掉数据库服务,cp数据文件的方法。但是一般少用,因为很多应用时不允许长时间停机的。
进行备份的操作如下: 停掉MySQL服务,在操作系统级别备份MySQL的数据文件和日志文件到备份目录。
进行恢复的操作如下:首先停掉MySQL服务,在操作系统级别恢复MySQL的数据文件;然后重启MySQL服务,使用mysqlbinlog工具恢复自备份以来的所有binlog。
二 热备份
1 MyISAM存储引擎
方法1 : 使用 mysqlhotcopy 工具
shell > mysqlhotcopy –u root –p 密码 数据库名 备份目录
eg:
David@David-VirtualBox:/usr/local/mysql/bin$ sudo ./mysqlhotcopy -u root -p 123 myisam /home/David/backup/myisam
[sudo] password for David:
Flushed 1 tables with read lock (`myisam`.`myisamtable`) in 0 seconds.
Locked 0 views () in 0 seconds.
Copying 2 files...
Copying indices for 0 files...
Unlocked tables.
mysqlhotcopy copied 1 tables (2 files) in 0 seconds (1 seconds overall).
方法2:手工锁表 copy
首先数据库中所有表加读锁:
mysql > flush tables for read;
然后 cp 数据文件到备份目录即可
2 InnoDB存储引擎
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26435490/viewspace-1302054/
,如需转载,请注明出处,否则将追究法律责任。