Reparar vs otimizar tabela no MySQL

5
  1. O Optimize inclui a tabela de reparos ou vice-versa internamente?
  2. É possível executar a tabela de reparo apenas se for encontrado corrompido, todas as ferramentas podem suportar isso?

(Eu estou usando o mecanismo de tabela MyISAM)

    
por Howard 11.05.2011 / 17:11

1 resposta

8
  • REPAIR TABLE Corrige a corrupção da tabela Problemas, como o identificador de arquivo aberto Conta, Resolução de Linhas com Dados de tamanho variável e assim por diante.
  • OPTIMIZE TABLE simplesmente copia o tabela para remover o espaço não utilizado. Se o tabela é MyISAM, ANALYZE TABLE é também realizado para atualizar o índice estatísticas para o bem da consulta Otimizador Se a tabela é InnoDB, ANALYZE TABLE é ignorado.

Você pode ter o mysqld auto check e reparar todas as tabelas MyISAM.

Na verdade, o livro Guia de Estudo de Certificação do MySQL 5.0 , Seção 30.5, Páginas 444,445 declara:

The MySQL server can be instructed to check and repair MyISAM tables automatically. With automatic repair enabled, the server checks each MyISAM table when it opens it to see whether the table was closed properly the last time it was used and is not marked as needing repair. If the table is not OK, the server repairs it.

To enable automatic MyISAM table maintenance, start the server with the --myisam-recover option, The option value can consist if a comma-separated list of one or more of the following values:

  • DEFAULT for the default checking.
  • BACKUP tells the server to make a backup of any table that is must change.
  • FORCE causes table recovery to be performed even if it would cause the loss of more than one row of data.
  • QUICK performs quick recovery : Tables that have no holes resulting from deletes or updates are skipped.

For example, to tell the server to perform a force recovery of MyISAM tables found to have problems but make a backup of any tables it changes, you can put the following lines in an option file:

[mysqld] myisam-recover=FORCE,BACKUP

Você também pode criar um arquivo chamado /root/StartUp.sql e colocar os comandos REPAIR TABLE que você deseja dentro. Em seguida, adicione init-file=/root/StartUp.sql a /etc/my.cnf e reinicie o mysql para acionar o script de inicialização.

    
por 11.05.2011 / 19:45

Tags