MySQL故障案例

來源:互聯網
上載者:User

標籤:mysql

第1章 MySQL故障案例:1.1 背景說明:

mysql的架構中沒有主從複製的體系,也沒有按時進行備份

資料庫中有兩個庫conf庫和jira庫,僅有一份備份的資料,還是一年前的備份

1.2 故障情境:

意外宕機,導致磁碟物理損壞,也就是說mysql軟體程式中data資料目錄中的jira檔案都沒有了

資料庫無法啟動,經過檢查,conf庫資料檔案都還在,也就是ibd和frm檔案都存在

領導要求,conf還是好的,能不能臨時先把資料庫跑起來,然後想辦法修複jira庫

1.3 故障環境類比:1.3.1 進入到data資料庫目錄下,刪除某一個庫的.ibd檔案
[[email protected] jiang]# pwd/application/mysql/data/jiang[[email protected] jiang]# lltotal 16-rw-rw---- 1 mysql mysql   61 Apr  3 19:01 db.opt-rw-rw---- 1 mysql mysql 8556 Apr  8 21:19 stu.frm-rw-rw---- 1 mysql mysql    0 Apr  8 21:25 stu.ibd[[email protected] jiang]# echo 123 >stu.ibd
1.3.2 重啟mysql服務
[[email protected] jiang]# /etc/init.d/mysqld  startStarting MySQL... ERROR! The server quit without updating PID file (/application/mysql/data/db01.pid).
1.4 臨時解決方案:1.4.1 搭建一個臨時節點,也就是mysql多執行個體,多執行個體的搭建這裡不進行示範,然後啟動多執行個體
[[email protected] 3307]# sh /server/scripts/mysql.sh startMySQL 3307  Starting                                       [  OK  ][[email protected] 3307]# ss -tunlp|grep 3307tcp    LISTEN     0      80       :::3307                 :::*                   users:(("mysqld",pid=5219,fd=11))
1.4.2 進入到資料庫,建立表結構

要恢複什麼表,需要建立好和故障前一樣的表結構,然後匯入.ibd檔案,否則無法匯入,

mysql> create table people (id int,name varchar(20));
1.4.3 刪除新建立的庫的.ibd檔案,因為沒有資料,一會要匯入新的資料
mysql> alter table people discard tablespace;Query OK, 0 rows affected (0.27 sec)
1.4.4 把.ibd檔案複製到多執行個體的資料庫目錄下,並授權給mysql使用者
[[email protected] zabbix]# cp -a ../people.ibd  .[[email protected] zabbix]# chown mysql.mysql people.ibd
1.4.5 重新匯入.ibd檔案
mysql> alter table people import tablespace;Query OK, 0 rows affected, 1 warning (0.34 sec)mysql> select * from people;+------+-----------------------------------------------------------------------------------------------------------------+| id   | name                                                                                                            |+------+-----------------------------------------------------------------------------------------------------------------+| NULL | ang  ??        1       ssd            1       angbo      (??        1       angbosd                        || NULL | NULL                                                                                                            || NULL | angbosd                                                                                                         || NULL | ssd            1       angbo     (??        1       angbosd                                                  |+------+-----------------------------------------------------------------------------------------------------------------+4 rows in set (0.00 sec)

查看錶中所有內容,已經可以看到資料了

說明:所以架構中,無論架構體系的大小,或者說資料存放區量的多少,該備份的一定要進行備份,這個懶偷不得

對於備份資料,可以定時全量備份sql檔案,或者把mysql服務做主從複製


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.