Categories
Uncategorized

Convert all your tabled From MyISAM to INNODB MySQL

This post shows exactly how to do, we will make use of a webserver and a php script to do the task but I guess you could do it through command line as well.

<?php
 # Connect
mysql_connect('localhost', 'root', 'pass') or die('Could not connect: ' . mysql_error());
 
# Choose a database
mysql_select_db('my_db') or die('Could not select database');

 $sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
 WHERE TABLE_SCHEMA = 'my_db' 
 AND ENGINE <> 'InnoDB'";

 $rs = mysql_query($sql);

 while($row = mysql_fetch_array($rs))
 {
 $tbl = $row[0];
 $sql = "ALTER TABLE $tbl ENGINE=INNODB";
 mysql_query($sql);
 }
?>