一、表损坏的愿意分析
一下原因是导致mysql表损坏的常见原因:
1、服务器突然断电导致数据文件损坏。
2、强制关机,没有先关闭mysql服务。
3、mysqld(mysqld是用来启动mysql数据库的命令
mysql是打开并执行sql语句的命令
这两个都在mysql安装文件夹的bin目录下)进程在写表时被杀掉。
4、使用mylsamchk的同时,mysqld也在操作表。
5、磁盘死机故障。
6、服务器死机。
7、mysql本身的bug.
二、表损坏的症状
一个损坏的标的经典症状如下:
1、当在表中选择数据之时,你得到的错误如下错误:
incorrect key file for table:'' try to repair it.
2、查询不能在不能在表中找到行或返回不完全的数据。
3、Error:Table 'p' is marked as crashed and should be
repaired.
4、打开表失败:Cann't open file 'xxx.MYI'(errno:145).
三、预防mysql表损坏可以采用以下手段预防mysql表损坏;
1、定期使用myisamchk 检车myisam表(注意关闭mysql),推荐使用chek table
来检查表(不用关闭mysqld)。
2、在做过大量的更新或删除操作之后,推荐使用OPTIMIZE TABLE
来优化表,这样既减少了文件碎片,又减少了表损坏的概率。
optimize table 是个好东西,很难说他能帮我们提高系统运行效率(具体的讨论可以盗这里看:http://www.xaprb.com/blog/2010/02/07/how-often-should-you-use-optimize-table/),但明显的是可以帮助我们回首更多的空间,减少碎片。官方是这么说的
OPTIMIZE TABLEshould be
used if you have deleted a large part of a table or if you have
made many changes to a table with variable-length rows (tables that
haveVARCHAR,VARBINARY,BLOB, orTEXTcolumns).
Deleted rows are maintained in a linked list and
subsequentINSERToperations
reuse old row positions. You can
useOPTIMIZE
TABLEto reclaim
the unused space and to defragment the data file. After extensive
changes to a table, this statement may also improve performance of
statements that use the table, sometimes
significantly.
1、回收空间Defragment