MySQL備份與恢復之熱拷貝(4)。本站提示廣大學習愛好者:(MySQL備份與恢復之熱拷貝(4))文章只能為提供參考,不一定能成為您想要的結果。以下是MySQL備份與恢復之熱拷貝(4)正文
在上一篇文章中我們提到熱備,熱備也就是在MySQL或許其他數據庫辦事在運轉的情形下停止備份。本文分享別的一種備份的辦法,也就是熱拷貝。熱拷貝跟熱備很相似,只不外熱備應用mysqldump敕令,熱拷貝應用mysqlhotcopy敕令。熱拷貝的優勢在於支撐辦事運轉中停止備份,速度快,機能好;優勢在於只能備份MyIsam的表,沒法備份InnoDB的表。所以在臨盆情況中應當酌情應用。
表示圖
熱備模仿
第一步,熱拷貝
[root@serv01 databackup]# mysqlhotcopy -uroot -p123456 --database larrydb > larrydb_hostcopy.sql Can't locate DBI.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/mysql/bin/mysqlhotcopy line 25. BEGIN failed--compilation aborted at /usr/local/mysql/bin/mysqlhotcopy line 25.
第二步,報錯。由於這個敕令是用perl寫的或許此敕令須要perl支撐,所以須要裝置perl
[root@serv01 databackup]# yum install perl* -y
第三步,對數據庫larrydb熱拷貝
[root@serv01 databackup]# mysqlhotcopy --help
#第一種寫法
[root@serv01 databackup]# mysqlhotcopy --user=root --password=123456 larrydb /databackup/
#第二種寫法
[root@serv01 databackup]# mysqlhotcopy -u root -p 123456 larrydb /databackup/ Flushed 2 tables with read lock (`larrydb`.`class`, `larrydb`.`stu`) in 0 seconds. Locked 0 views () in 0 seconds. Copying 5 files... Copying indices for 0 files... Unlocked tables. mysqlhotcopy copied 2 tables (5 files) in 0 seconds (0 seconds overall).
第四步,模仿數據喪失
[root@serv01 databackup]# ll larrydb total 36 -rw-rw----. 1 mysql mysql 8590 Sep 10 19:07 class.frm -rw-rw----. 1 mysql mysql 65 Sep 10 19:07 db.opt -rw-rw----. 1 mysql mysql 8618 Sep 10 19:07 stu.frm -rw-rw----. 1 mysql mysql 48 Sep 10 19:07 stu.MYD -rw-rw----. 1 mysql mysql 1024 Sep 10 19:07 stu.MYI mysql> use larrydb; Database changed mysql> show tables; +-------------------+ | Tables_in_larrydb | +-------------------+ | class | | stu | +-------------------+ 2 rows in set (0.00 sec) mysql> show create table class \G; *************************** 1. row *************************** Table: class Create Table: CREATE TABLE `class` ( `cid` int(11) DEFAULT NULL, `cname` varchar(30) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec) ERROR: No query specified mysql> show create table stu \G; *************************** 1. row *************************** Table: stu Create Table: CREATE TABLE `stu` ( `sid` int(11) DEFAULT NULL, `sname` varchar(30) DEFAULT NULL, `cid` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 1 row in set (0.00 sec) ERROR: mysql> drop table class,stu; Query OK, 0 rows affected (0.01 sec) mysql> show tables; Empty set (0.00 sec) #如許刪除會失足,不要如許刪除 [root@serv01 databackup]# rm -rf /usr/local/mysql/data/larrydb/* [root@serv01 databackup]# rm -rf /usr/local/mysql/data/larrydb/
第五步,恢單數據
[root@serv01 databackup]# cp larrydb /usr/local/mysql/data/ -arvf `larrydb' -> `/usr/local/mysql/data/larrydb' `larrydb/stu.MYI' -> `/usr/local/mysql/data/larrydb/stu.MYI' `larrydb/stu.MYD' -> `/usr/local/mysql/data/larrydb/stu.MYD' `larrydb/stu.frm' -> `/usr/local/mysql/data/larrydb/stu.frm' `larrydb/db.opt' -> `/usr/local/mysql/data/larrydb/db.opt' `larrydb/class.frm' -> `/usr/local/mysql/data/larrydb/class.frm' mysql> use larrydb; Database changed mysql> show tables; +-------------------+ | Tables_in_larrydb | +-------------------+ | class | | stu | +-------------------+ 2 rows in set (0.00 sec) mysql> select * from class; ERROR 1146 (42S02): Table 'larrydb.class' doesn't exist mysql> select * from stu; +------+---------+------+ | sid | sname | cid | +------+---------+------+ | 1 | larry01 | 1 | | 2 | larry02 | 2 | +------+---------+------+ 2 rows in set (0.00 sec) mysql> drop database larrydb; Query OK, 2 rows affected (0.00 sec) #再次導入 [root@serv01 databackup]# mysql -uroot -p123456 < larrydb.sql mysql> use larrydb; Database changed mysql> show tables; +-------------------+ | Tables_in_larrydb | +-------------------+ | class | | stu | +-------------------+ 2 rows in set (0.00 sec) mysql> select * from stu; +------+---------+------+ | sid | sname | cid | +------+---------+------+ | 1 | larry01 | 1 | | 2 | larry02 | 2 | +------+---------+------+ 2 rows in set (0.00 sec) mysql> select * from class; +------+--------+ | cid | cname | +------+--------+ | 1 | linux | | 2 | oracle | +------+--------+ 2 rows in set (0.00 sec)
本文引見了另外一種備份--熱拷貝,與熱備的差別在於應用的敕令分歧,熱拷貝應用mysqlhotcopy敕令,願望年夜家可以親身著手操作一下!