简体   繁体   English

使用`Repair Table` vs myisamchk修复mysql myisam表

[英]Repairing mysql myisam table using `Repair Table` vs myisamchk

I am working on a script that will be a cronjob that will look at the tables in database and repair any that need it. 我正在编写一个脚本,它将是一个cronjob,它将查看数据库中的表并修复任何需要它的表。 They are myisam tables in a mysql database. 它们是mysql数据库中的myisam表。 My question, is there any reason to use myisamchk syntax on the command line vs REPAIR TABLE query syntax? 我的问题是,有没有理由在命令行和REPAIR TABLE查询语法中使用myisamchk语法?

On a myisam documentation page, http://dev.mysql.com/doc/refman/5.0/en/myisamchk.html , they provide this as a way to repair all tables that need it 在myisam文档页面http://dev.mysql.com/doc/refman/5.0/en/myisamchk.html上 ,他们提供了这种方法来修复所有需要它的表

myisamchk --silent --force --fast --update-state \
          --key_buffer_size=64M --sort_buffer_size=64M \
          --read_buffer_size=1M --write_buffer_size=1M \
          /path/to/datadir/*/*.MYI

would that have a different result than using 会有不同于使用的结果

REPAIR TABLE tablename

on all of my tables? 在我的所有桌子上? I would do it programatically with php and end up with something like (pseudocode) 我会用PHP编程,最后得到类似(伪代码)的东西

$tables=query("SELECT table from information_schema.tables where table_schema='myDBName'");
foreach($tables as $table)
{
    $result=query("REPAIR TABLE ".$table);
}

Notwithstanding any opinions on the practicality of doing it one way or the other, but would the actual end result be different? 尽管对于以某种方式这样做的实用性有任何意见,但实际的最终结果是否会有所不同? Thanks. 谢谢。

I can provide working (non-pseudo) php code if needed but I didn't think it was necessary. 如果需要,我可以提供工作(非伪)PHP代码,但我认为没有必要。 The reason I am using pseudocode is that at work we use our own wrapper for db access. 我使用伪代码的原因是,在工作中我们使用自己的包装器进行数据库访问。

You shouldn't have to be repairing tables so often that automation is needed. 您不必经常修理表,因此需要自动化。 You probably shouldn't be using MyISAM at all. 你根本不应该使用MyISAM。 But if you insist, the answers are mostly from the page you linked to: 但如果你坚持,答案主要来自你链接到的页面:

Caution 警告

It is best to make a backup of a table before performing a table repair operation; 最好在执行表修复操作之前备份表; under some circumstances the operation might cause data loss. 在某些情况下,操作可能会导致数据丢失。 Possible causes include but are not limited to file system errors. 可能的原因包括但不限于文件系统错误。

...which, if course, could also be the original cause of the problem... this sounds to me like another vote against automating this process. ...当然,这也可能是问题的原因......这听起来像是另一次投票反对自动化这个过程。

Important 重要

You must ensure that no other program is using the tables while you are running myisamchk. 在运行myisamchk时,必须确保没有其他程序正在使用这些表。 The most effective means of doing so is to shut down the MySQL server while running myisamchk, or to lock all tables that myisamchk is being used on. 这样做的最有效方法是在运行myisamchk时关闭MySQL服务器,或锁定myisamchk正在使用的所有表。

So while the two ways of repairing tables are from a common base of code, it seems like eou should be using REPAIR TABLE unless the server is offline. 因此,虽然修复表的两种方法来自共同的代码基础,但似乎应该使用REPAIR TABLE除非服务器处于脱机状态。 Note ask that this command also has options. 请注意,此命令也有选项。

http://dev.mysql.com/doc/refman/5.6/en/repair-table.html http://dev.mysql.com/doc/refman/5.6/en/repair-table.html


Update: I almost hate to add this, because it is entirely anecdotal, but I have long suspected that repairing a MyISAM table may not always find every possible thing that could be wrong with a table, leading you to think it has been repaired because it's usable again. 更新:我几乎不想添加这个,因为它完全是轶事,但我一直怀疑修复MyISAM表可能并不总能找到表格可能出错的所有可能的东西,导致你认为它已被修复,因为它是再次使用。 Anything short of using the full-blown extended repair, to me, seems like you're taking a risk, and I would be most inclined to actually force a full rebuild of the entire table, with something like this, if you have a problematic table: 对我来说,任何不能使用全面扩展修复的东西,似乎都冒了风险,如果你遇到问题,我最倾向于强制完全重建整个桌子。表:

ALTER TABLE t1 ENGINE=InnoDB;
ALTER TABLE t1 ENGINE=MyISAM;

This would completely remove all traces of the former table and leave you with a shiny new one. 这将完全删除前表的所有痕迹,并留下一个闪亮的新表。 Be sure you have innodb_file_per_table set to 1 first, or you will allocate disk space to the ibdata1 system namespace, which can't easily be reclaimed. 确保首先将innodb_file_per_table设置为1,否则您将为ibdata1系统命名空间分配磁盘空间,这不能轻易回收。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM