备份MySQL出现Can\'t open file when using LOCK TABLES错误

2016年11月8日

近日查看了下自己的mysql 备份,进入备份的目录发现有几个库的文件相当小 , 于是将其拉取到本地导入发现是个错误的文件 ,在看其他(至少是以KB计算的 *KB),发现没问题。
然后跑了一边脚本得看到如下问题 :

[root@newserver14116 task]# ./mysql-backup.sh
Start to Backup...
mysqldump: Got error: 145: Table './af/af_005_comments' is marked as crashed and should be repaired when using LOCK TABLES
mysqldump: Got error: 23: Out of resources when opening file './glasses/glasses_087_comments.MYD' (Errcode: 24) when using LOCK TABLES
mysqldump: Got error: 145: Table './prada/prada_015_comments' is marked as crashed and should be repaired when using LOCK TABLES
mysqldump: Got error: 1016: Can't open file: './wedding/wedding_046_postmeta.frm' (errno: 24) when using LOCK TABLES
BackUp Success!
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

网上查阅了下 这种错可以采用强制导出

--lock-tables=false

使用方法: mysqldump -u root -pMyPassword DbName --lock-tables=false > data.sql

这样表示忽略mysqldump 的错误,强制导出

还有一种方法就是修复表

首先查看表 check

mysql> check table prada_015_comments;
+--------------------------+-------+----------+--------------------------------------------------------------------------------------------+
| Table                    | Op    | Msg_type | Msg_text                                                                        |
+--------------------------+-------+----------+--------------------------------------------------------------------------------------------+
| prada.prada_015_comments | check | warning  | Table is marked as crashed                                    |
| prada.prada_015_comments | check | error    | Size of datafile is: 1089536         Should be: 1090112 |
| prada.prada_015_comments | check | error    | Corrupt                                                                |
+--------------------------+-------+----------+--------------------------------------------------------------------------------------------+
3 rows in set (0.00 sec)

repair   修复表

mysql> repair table prada_015_comments;
+--------------------------+--------+----------+------------------------------------------------------------------------------------------+
| Table                    | Op     | Msg_type | Msg_text                                                                      |
+--------------------------+--------+----------+------------------------------------------------------------------------------------------+
| prada.prada_015_comments | repair | info     | Found block that points outside data file at 1088852   |
| prada.prada_015_comments | repair | status   | OK                                                                      |
+--------------------------+--------+----------+------------------------------------------------------------------------------------------+
2 rows in set (0.13 sec)mysql> check table prada_015_comments;
+--------------------------+-------+----------+-----------------------------+
| Table                    | Op    | Msg_type | Msg_text         |
+--------------------------+-------+----------+-----------------------------+
| prada.prada_015_comments | check | status   | OK       |
+--------------------------+-------+----------+-----------------------------+
1 row in set (0.01 sec)

没有评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注