我有一个使用 MySQL 数据库的程序。备份用 完成mysqlhotcopy --noindices
,恢复用 完成myisamchk --recover
。
恢复时,我收到原始索引文件大于 2048 字节的表的错误:
myisamchk: Unknown error 126: '/var/lib/mysql/bak/foo.MYI' doesn't have a correct index definition. You need to recreate it before you can do a repair
以下是一个最简单的例子:
$ mysql db <<< 'truncate table foo;'
$ ls -l /var/lib/mysql/db/foo.MYI
-rw-r--r-- 1 mysql mysql 3072 Jul 21 01:02 /var/lib/mysql/db/foo.MYI
$ mysqlhotcopy --noindices db bak
$ ls -l /var/lib/mysql/bak/foo.MYI
-rw-r--r-- 1 mysql mysql 2048 Jul 21 01:02 /var/lib/mysql/bak/foo.MYI
$ myisamchk -r /var/lib/mysql/bak/foo.MYI
myisamchk: Unknown error 126: '/var/lib/mysql/bak/foo.MYI' doesn't have a correct index definition. You need to recreate it before you can do a repair
在文档中我只发现了这一点:
$ perldoc /usr/bin/mysqlhotcopy
--noindices Don’t include index files in copy. Only up to the first 2048 bytes are copied; You can restore the indexes with isamchk -r or myisamchk -r on the backup.
为何无法myisamchk
恢复数据库?
使用 mysql 5.1.73、mysqlhotcopy 1.23、myisamchk-2.7。
答案1
删除.MYI 文件,然后修复表。
和认真考虑改为 InnoDB(从 MyISAM 开始)。