Batch convert table engine from innodb to MyISAM in innodb database.

Published: 2013-04-03

```html

Save the following file as mysql.php, modify the corresponding database username, database name, and password. Upload it to the website, access this page, and it will batch convert table engines to MYISAM.

<?php

//Connect to database

$host='localhost';

$user='mysql_username';   //Database username

$passwd='mysql_password'; //Password

$db='wordpressdb';  //Database name

$link= mysql_connect($host,$user,$passwd);

if (!$link) {

die('Could not connect: '.mysql_error() );

}

 

mysql_select_db( $db,$link ) or die ('can\'t use'. $db . mysql_error());

$result=mysql_query("show tables ") or die( mysql_error());

while($row=mysql_fetch_row($result)){

#echo $row[0];

#var_dump($row);

echo "$row[0] \n";

mysql_query("alter table  $row[0] type='MYISAM'") or die (mysql_error());

}

#var_dump($result);

mysql_close($link);

?>

Note: Before conversion, please first use database software to make an sql file backup of the database to avoid problems during conversion. If the transfer fails, please check whether “default-storage-engine” in my.ini is = “MyISAM”. Also, all risks caused by this conversion shall be borne by yourself.

```