mysqlsqlinnodb

How to convert all tables from MyISAM into InnoDB?


I know I can issue an alter table individually to change the table storage from MyISAM to InnoDB.

I am wondering if there is a way to quickly change all of them to InnoDB?


Solution

  • <?php
        // connect your database here first 
        // 
    
        // Actual code starts here 
    
        $sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
            WHERE TABLE_SCHEMA = 'your_database_name' 
            AND ENGINE = 'MyISAM'";
    
        $rs = mysql_query($sql);
    
        while($row = mysql_fetch_array($rs))
        {
            $tbl = $row[0];
            $sql = "ALTER TABLE `$tbl` ENGINE=INNODB";
            mysql_query($sql);
        }
    ?>