Change Storage Engine from INNODB to MyISAM for all tables

The following is a basic php script to change the storage engine used by all MySQL tables for a specified database to MyISAM from INNODB.



<?php

$conn = mysql_connect("localhost","username","password");
mysql_select_db("database-name",$conn);

$sql = "SHOW tables";
$rs = mysql_query($sql);

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


To change all tables from MyISAM to INNODB

<?php

$conn = mysql_connect("localhost","username","password");
mysql_select_db("database-name",$conn);

$sql = "SHOW tables";
$rs = mysql_query($sql);

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

Comments

Popular posts from this blog

ActiveMQ, easy to use open source message oriented middleware (MOM)

Basic Send Message to MQ with Java and IBM MQ JMS

MySQL Error Invalid Table or Database Name