friky.com
← Back to archive

Post

Como transformar tablas MyISAM a InnoDB masivamente en MySQL

2013-02-18 Agustí Pons Original post

He encontrado este truco en StackOverflow funciona bien con tablas relativamente pequeñas, del orden de Megas, si pasamos a tablas de Gigas el tema empieza a tardar y ya tienes que hacer algun tipo de exportación e importación.

El script:

SELECT CONCAT('ALTER TABLE `',table_schema,'`.'
,table_name,' ENGINE=InnoDB;') InnoDBConversionSQL
FROM information_schema.tables
WHERE engine='MyISAM' AND table_schema NOT IN
('information_schema','mysql','performance_schema')
ORDER BY (data_length+index_length);

Si quereis ver el tamaño de cada tabla antes de ejecutarlo:

SELECT CONCAT('ALTER TABLE `',table_schema,'`.'
,table_name,' ENGINE=InnoDB;') InnoDBConversionSQL
, data_length+index_length
FROM information_schema.tables
WHERE engine='MyISAM' AND table_schema NOT IN
('information_schema','mysql','performance_schema')
ORDER BY (data_length+index_length);

Recomiendo siempre empezar por las primeras tablas (más pequeñas) e ir subiendo, hasta que veamos que el proceso tarda demasiado.