[原創]CentOS下Mysql的日誌復原

來源:互聯網
上載者:User

標籤:

一、    環境:

a)        Centos-6.5-x64位作業系統。

b)        安裝mysql。命令:yum install mysql*

二、    配置

a)        配置/etc/my.cnf檔案

[mysqld]

       Log-bin=bin-log   //配置開啟日誌功能

三、    實現

  1. 查看/var/lib目錄下沒有類似bin-log.000001的記錄檔。
  2. 登入mysql執行:flush logs;//重新整理日誌,再查看則有記錄檔了,此時若沒有再執行flush logs和重啟mysql,那麼一切對mysql的操作都將記錄在重新整理後出現的記錄檔中。命令:mysqlbinlog –no-defaults bin-log.000001 | more
  3. 登入mysql,建立表和插入一系列測試資料作為要恢複的對象。再執行一次flush logs,產生bin-log.000002記錄檔。然後將資料和表刪除。
  4. 現在將資料恢複。開啟另一個終端,執行命令:

    Mysqlbinlog –no-defaults bin-log.000001 | mysql –u root –p

  斷行符號輸入root密碼。返回查看,表和資料均已恢複。

四、    mysqlbinlog文法:基於時間(date)和位置(position)的恢複

  1.定位: --start-position 開始點

    --stop-position 結束點

    --start-date 開始時間

    --stop-date  結束時間

  2.例:

    Mysqlbinlog –no-defaults –start-position pos值 –stop-position pos值 bin-log.000001 | mysql –u root –p

 

  註:定位關鍵字可以配對使用也可單獨使用,實現現象略。

[原創]CentOS下Mysql的日誌復原

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.