2.8.1.3. Convert storage of all tables

Attention!

It is not recommended to use this method for large databases.

To change the storage type of all database tables, you can run a script that will execute the necessary SQL query for each individual table.

<?php
$DB = array(
    'host' => 'example.mysql.tools',
    'user' => 'example_db',
    'password' => 'xxxxxxxxxx',
    'database' => 'example_db',
    'engine' => 'InnoDB'
);
$link = mysqli_connect($DB['host'], $DB['user'], $DB['password'], $DB['database']);
$sql = "SHOW TABLES";
$query = mysqli_query($link, $sql);
while ($row = mysqli_fetch_assoc($query)) {
    if (mysqli_query($link, "ALTER TABLE `".$row['Tables_in_'.$DB['database']]."` ENGINE = ".$DB['engine'])) {
        echo $row['Tables_in_'.$DB['database']]." ok<br>";
    } else {
        echo $row['Tables_in_'.$DB['database']]." error<br>";
    }
}

In the script, use your data for connecting to the database:

  • host — database server.
  • user — database user name.
  • password — database user password.
  • database — database name.
  • engine — type of storage to be set.
Content