2.8.1.3. Converting storage of all tables

Requirements: PHP 5+

To convert all tables, you can torun a script that will execute an SQL query for each individual table.

  1. <?php
  2. $DB = array(
  3. 'host' => 'example.mysql.tools',
  4. 'user' => 'example_db',
  5. 'password' => 'xxxxxxxxxx',
  6. 'database' => 'example_db',
  7. 'engine' => 'InnoDB'
  8. );
  9. $link = mysqli_connect($DB['host'], $DB['user'], $DB['password'], $DB['database']);
  10. $sql = "SHOW TABLES";
  11. $query = mysqli_query($link, $sql);
  12. while ($row = mysqli_fetch_assoc($query)) {
  13. if (mysqli_query($link, "ALTER TABLE `".$row['Tables_in_'.$DB['database']]."` ENGINE = ".$DB['engine'])) {
  14. echo $row['Tables_in_'.$DB['database']]." ok<br>";
  15. } else {
  16. echo $row['Tables_in_'.$DB['database']]." error<br>";
  17. }
  18. }

In the script you need to specify connection data to the database:

  1. host — database server.
  2. user — the name of the database user.
  3. password — database user password.
  4. database — the name of the database.
  5. engine — the target storage type to which all tables will be changed.

Alternative ways of changing the storage type are described here.

Content