如何将 MyISAM 中的所有表转换为 InnoDB?

2021-11-20 00:00:00 sql mysql innodb

我知道我可以单独发出一个更改表来将表存储从 MyISAM 更改为 InnoDB.

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

我想知道是否有办法快速将它们全部更改为 InnoDB?

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

推荐答案

<?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);
    }
?>

相关文章