MySQL備份與恢複之熱拷貝

來源:互聯網
上載者:User

在上一篇文章中我們提到熱備(),熱備也就是在MySQL或者其他資料庫服務在啟動並執行情況下進行備份。本文分享另外一種備份的方法,也就是熱拷貝。熱拷貝跟熱備很類似,只不過熱備使用mysqldump命令,熱拷貝使用mysqlhotcopy命令。熱拷貝的優勢在於支援服務運行中進行備份,速度快,效能好;劣勢在於只能備份MyIsam的表,無法備份InnoDB的表。所以在生產環境中應該酌情使用。

 

三 熱備類比

 

 

第一步,熱拷貝

[root@serv01 databackup]# mysqlhotcopy -uroot -p123456 --database larrydb > larrydb_hostcopy.sqlCan'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 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.MYImysql> use larrydb;Database changedmysql> show tables;+-------------------+| Tables_in_larrydb |+-------------------+| class             || stu               |+-------------------+2 rows in set (0.00 sec)mysql> show create table class \G;*************************** 1. row ***************************       Table: classCreate Table: CREATE TABLE `class` (  `cid` int(11) DEFAULT NULL,  `cname` varchar(30) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin11 row in set (0.00 sec)ERROR: No query specifiedmysql> show create 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=MyISAM DEFAULT CHARSET=latin11 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/

更多詳情見請繼續閱讀下一頁的精彩內容:

MySQL備份和恢複具體實施

MySQL備份:mylvmbackup介紹與使用

Linux下通過mysqldump備份MySQL資料庫成sql檔案

Linux中使用mysqldump對MySQL資料庫進行定時備份

磁碟管理——LVM

  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.