MySQL table is marked as crashed

两盒软妹~` 提交于 2019-12-01 03:01:25

问题


I fairly new to MySQL database. I am repeatedly seeing an error from MySQL saying the table is marked as crashed and should be repaired. However I am able to repair the crashed table by using the command myisamchk. By the way, I am using MYISAM database engine in MySQL.

I just wanted to know under what circumstances would a DB table crash and how I can prevent it from happening again?

I am connecting to MySQL(5.0) database from Tcl (8.5) script using mysqltcl library (3.0).


回答1:


MyISAM tables are very easy to crash. There is header info in each table that keeps track of how many open file handles a MyISAM table has.

If mysqld crashes, any MyISAM table that had open file handles to it never had the opportunity to decrement the file handle count upon each file handle closing. Thus, if a new file handle opens a MyISAM table (.MYD file) and mysqld discovers a mismatch between the number of file handles a MyISAM table believes is open and the the number of file handles the MyISAM table actually has open, the table is declared crashed.

There are four(4) methods for handling this:

METHOD #1 : Setup automatic MyISAM repair

See my post https://dba.stackexchange.com/a/15079/877 on how to set this up upon a MySQL restart (Mar 15, 2012)

METHOD #2 : Use InnoDB instead of MyISAM

InnoDB has crash recovery built into the Storage Engine's initialization. MyISAM does not

METHOD #3 : Use Aria instead of MyISAM

Aria is MariaDB's drop-in replacement for MyISAM. It features crash recovery mechanisms for individual tables.

METHOD #4 : Don't kill -9 on mysqld

If mysqld crashes, deliberately or involuntarily, header info for all open MyISAM tables will get them into a crashed state. Avoid having to manually kill mysqld.



来源:https://stackoverflow.com/questions/11869377/mysql-table-is-marked-as-crashed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!