示意圖熱備模擬
第一步,熱拷貝
?123[root@serv01 databackup]# mysqlhotcopy -uroot -p123456--database larrydb > larrydb_hostcopy.sqlcan't locate dbi.pmin @inc (@inccontains: /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
?1[root@serv01 databackup]# yum install perl* -y
第三步,對資料庫larrydb熱拷貝
?1[root@serv01 databackup]# mysqlhotcopy--help
#第一種寫法
?1[root@serv01 databackup]# mysqlhotcopy--user=root --password=123456 larrydb /databackup/
#第二種寫法
?12345678[root@serv01 databackup]# mysqlhotcopy -u root -p 123456 larrydb /databackup/ flushed 2 tableswith read lock (`larrydb`.`class`, `larrydb`.`stu`)in 0 seconds.locked 0 views ()in 0 seconds.copying 5 files...copying indicesfor 0 files...unlocked tables.mysqlhotcopy copied 2 tables (5 files)in 0 seconds (0 seconds overall).
第四步,模擬資料丟失
?[root@serv01 databackup]# ll larrydbtotal 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 changedmysql> show tables;+-------------------+| tables_in_larrydb |+-------------------+| class || stu |+-------------------+2rows in set (0.00 sec) mysql> showcreate table class \g;*************************** 1. row ***************************table: classcreate table:create table `class` (`cid`int(11)default null,`cname`varchar(30)default null) engine=innodbdefault charset=latin11 rowin set (0.00 sec) error:no query specified mysql> showcreate table stu \g;*************************** 1. row ***************************table: stucreate table:create table `stu` (`sid`int(11)default null,`sname`varchar(30)default null,`cid`int(11)default null) engine=myisamdefault charset=latin11 rowin set (0.00 sec) error: mysql>drop table class,stu;query ok, 0rows affected (0.01 sec) mysql> show tables;emptyset (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 changedmysql> show tables;+-------------------+| tables_in_larrydb |+-------------------+| class || stu |+-------------------+2rows in set (0.00 sec) mysql>select *from class;error 1146 (42s02):table 'larrydb.class' doesn't existmysql>select *from stu;+------+---------+------+| sid | sname | cid |+------+---------+------+| 1 | larry01 | 1 || 2 | larry02 | 2 |+------+---------+------+2rows in set (0.00 sec) mysql>drop database larrydb;query ok, 2rows affected (0.00 sec) #再次匯入[root@serv01 databackup]# mysql -uroot -p123456 < larrydb.sql mysql> use larrydb;database changedmysql> show tables;+-------------------+| tables_in_larrydb |+-------------------+| class || stu |+-------------------+2rows in set (0.00 sec) mysql>select *from stu;+------+---------+------+| sid | sname | cid |+------+---------+------+| 1 | larry01 | 1 || 2 | larry02 | 2 |+------+---------+------+2rows in set (0.00 sec) mysql>select *from class;+------+--------+| cid | cname |+------+--------+| 1 | linux || 2 | oracle |+------+--------+2rows in set (0.00 sec)
mysql熱拷貝 MySQL備份與恢復之熱拷貝
熱備也就是在mysql或者其他資料庫服務在執行的情況下進行備份。本文分享另外一種備份的方法,也就是熱拷貝。熱拷貝跟熱備很類似,二 示意圖 三 熱備模擬 第一步,熱拷貝 root serv01 databackup mysqlhotcopy uroot p123456 database larrydb...
mysql 缺點熱備份 mysql 熱備份
xtrabackup mysql 的備份和恢復 1.準備 安裝依賴 yum install perl dbd mysql perl time hires libaio libaio devel y wget 2.安裝 tar zxf percona xtrabackup 2.2.3 4982 lin...
mysql邏輯備份是熱備份嗎 mysql的備份原理
1.冷備份 原理 關閉mysql伺服器,然後將data目錄下面的所有檔案進行拷貝儲存,需要恢復時,則將目錄拷貝到需要恢復的機器即可 2.快照備份 原理 將所有的資料庫檔案放在同一分割槽中,然後對該分割槽執行快照工作,對於linux而言,需要通過lvm logical volumn manager 來...