Convert MyISAM tables to InnoDB

Convert MyISAM tables to InnoDB

If you want to convert a MyISAM table to InnoDB, the process is fairly easy, but you can do something extra to speed things up. Before converting the table, adjust its order so that the primary key column is in order:

ALTER TABLE tablename ORDER BY 'primary_key_column';

This will pre-arrange the table so that it can be converted quickly without a lot of re-arranging required in MySQL. Then, simply change the table engine:

ALTER TABLE tablename ENGINE = INNODB;

If your table is large, then it may take a while to convert it over. There will probably be a fair amount of CPU usage and disk I/O in the process.

These statements are also safe in replicated environments. When you issue this statement to the master, it will begin the conversion process. Once it is complete on the master, the statement will roll down to the slaves, and they will begin the conversion as well. Keep in mind, however, that this can greatly reduce the performance of your configuration in the process.

http://major.io/2007/10/03/convert-myisam-tables-to-innodb/

http://www.oficinadanet.com.br/artigo/mysql/mysql-como-converter-innodb-para-myisam

 

 

Para alterar a tabela teste para InnoDB execute o seguinte comando:


ALTER TABLE `teste` ENGINE = InnoDB

Para fazer o contrário, transformar InnoDB para MyISAM execute o seguinte comando:


ALTER TABLE `teste` ENGINE = MYISAM

Como alterar então os tipos usando o phpMyAdmin:

No phpMyAdmin, crie uma tabela chamada teste, com os campos id INT(11) e titulo VARCHAR(200), conforme figura abaixo:

http://www.oficinadanet.com.br//imagens/coluna/3369//img1.png

Defina o nome da tabela teste e clique em executar. Após isto aparecerá uma tela pedindo para colocar os campos, conforme tela abaixo:

http://www.oficinadanet.com.br//imagens/coluna/3369//img2.png

Defina o nome dos campos id INT(11) e faça ele como chave primária, e outro campo chamado titulo VARCHAR(200). Você pode definir o tipo da tabela, no caso escolhi MyISAM. E depois clique em executar.

Feito isto, acesse a tabela teste, na barra lateral esquerda, e então clique na aba operações, vai ter uma caixa chamada Opções da tabela, tem um campo chamado Storage Engine, basta escolher o tipo que quiser para alterar e apertar o botão executar, conforme a figura abaixo:

http://www.oficinadanet.com.br//imagens/coluna/3369//img3.png

 

Atenção: Certifique-se de que você não irá ocupar todo o tablespace: tabelas InnoDB gasta muito mais espaço que tabelas MyISAM. Se um ALTER TABLE ficar sem espaço, ele irá iniciar um rollback, que pode levar horas se ele estiver no limite de disco. Para inserções, o InnoDB utiliza o buffer de inserção para fundir registros de índices secundários a índices em grupos. Isto economiza muito a E/S de disco.

Qualquer dúvida pergunte no formulário abaixo 😉

Deixe um comentário