InnoDB 中文參考手冊 --- 15 故障檢測與修復 (轉)

amyz發表於2007-08-15
InnoDB 中文參考手冊 --- 15 故障檢測與修復 (轉)[@more@] words" content="My,InnoDB,4.1.0,Shuixin13, 4.1.0,中文,中文參考手冊,犬犬(心帆)"> CSS rel=STYLESHEET>

  • 一個普遍的規則就是當一個操作挫敗或你懷疑是一個 ,你必須檢視 MySQL 服務 mysqld 的錯誤日誌(error log),通常命名為 'hostname'.err,或 下的 mysql.err
  • 當進行故障檢測並修復時,在命令提示符下執行 MySQL 服務程式 mysqld 是一個較好的方式,不要透過 safe_mysqld 的包裝(wrapper)或以 Windows 服務啟動。你可以看到 mysqld 在命令提示符視窗上的顯示,而可以更好地把握什麼將要發生。在 Windows 下,你必須以 --console 選項執行 mysqld-max 來使輸出直接顯示在 MS-D提示符視窗上。
  • 如果問題與有關(performance-related),或你的服務看起來將要掛起,你可以使用 innodb_monitor 來顯示 InnoDB 內部狀態的相關資訊。如果問題是由於鎖定引起,使用 innodb_lock_monitor。如果問題是在建表時或其它的資料字典操作,使用 innodb_table_monitor 顯示 InnoDB 內部資料字典的內容。
  • 如果你懷疑表已損壞,在表上執行 CHECK TABLE

發現並修復資料字典錯誤的操作

一個特殊的有關表的問題就是 MySQL 在它自己的資料目錄下的 .frm 中儲存它自己的資料字典資訊,然而 InnoDB 將它自己的資訊儲存在資料檔案中 InnoDB 自己的資料字典中。如果你在外部移走了 .frm 檔案,或在 MySQL < 3.23.44 的版本中使用了 DROP DATABASE ,或在資料字典操作時崩潰了,那麼 .frm 檔案可能會因與 InnoDB 內部的資料字典 out-of-sync 而結束。

與資料字典 out-of-sync 的一個故障現象就是 CREATE TABLE 語句的失敗。那麼你必須檢視錯誤日誌。如果錯誤述說為表在 InnoDB 內部資料字典中已存在,那麼一定在 InnoDB 的資料檔案中存在一個孤表(orphaned table),沒有相對應的 .frm 檔案。

InnoDB: Error: table test/parent already exists in InnoDB internal InnoDB: data dictionary. Have you deleted the .ffile InnoDB: and not used DROP TABLE? Have you used DROP DATABASE InnoDB: for InnoDB tables in MySQL version <= 3.23.43? InnoDB: See the Restrictions section of the InnoDB manual. InnoDB: You can drop the orphaned table ins InnoDB by InnoDB: creating an InnoDB table with the same name in another InnoDB: database and moving the .frm file to the current database. InnoDB: Then MySQL thinks the table exists, and DROP TABLE will InnoDB: succeed.

你可以跟從上面錯誤日誌中的提示移除(drop)孤表(orphaned table)。

 

另一個與資料字典 out-of-sync 的故障現象就是 MySQL 提示不能開啟一個檔案 yourtablename.InnoDB 的錯誤。

ERROR 1016: Can't open file: 'child2.InnoDB'. (errno: 1)

在錯誤日誌中可以發現:

InnoDB: Cannot find table test/child2 from the internal data dictionary InnoDB: of InnoDB though the .frm file for the table exists. Maybe you InnoDB: have deleted and recreated InnoDB data files but have forgotten InnoDB: to delete the corresponding .frm files of InnoDB tables?

意思就是有一個孤的(orphaned) .frm 檔案,在 InnoDB 中沒有相應的表與之對應。可以透過手工刪除 .frm 檔案來移除它。

 

如果在一個 ALTER TABLE 操作時 MySQL 崩潰了,你可能會因在 InnoDB 表空間在存在一個孤的臨時表而告終。透過 innodb_table_monitor ,你可以發現一個名為 #sql... 的表,但是 MySQL 不允許訪問任何一個如此命名的表,你將不能轉儲(dump)或移除(drop)它。解決辦法就是使用從 3.23.48 開始 InnoDB 支援的一個特殊的機制。

如果在表空間在一個孤表(orphaned table) #sql... ,那麼呼叫

CREATE TABLE `rsql..._recover_innodb_tmp_table`(...) type = innodb;


使表定義與臨時表相似,你可以使 InnoDB 將孤表重新命名為 `rsql..._recover_innodb_tmp_table`。那麼你就可以轉儲或移除重新命名後的表了。 表名中的反引號是必須的,因為臨時表命名中包含字元 '-'

 


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752019/viewspace-957811/,如需轉載,請註明出處,否則將追究法律責任。

相關文章