mysql 批量调整数据表引擎为 InnoDB

mysql 批量调整数据表引擎:

<?php

//连接数据库
$host='localhost';
$user='root';   //数据库用户名
$passwd='root'; //密码
$db='hunlian';  //数据库名称

$link= mysqli_connect($host, $user, $passwd, $db);

if (!$link) {
    die("连接错误: " . mysqli_connect_error());
}
 
$result=$link->query("SHOW TABLES ") or die( $link->error());
$num = 0;
if ($result->num_rows > 0) {
    // 输出数据
    while($row = $result->fetch_assoc()) {
        // {"Tables_in_www_hunlian_com":"zeai_315"}
        $table_name = $row['Tables_in_hunlian'];//键值需调整为数据库名
        $link->query("ALTER TABLE  $table_name ENGINE='InnoDB'");
        $num ++;
        echo $table_name . "sucess! <br/>";
    }
}

echo "total:" .$num;

$link->close();

 

posted @ 2026-01-07 10:54  流浪2024  阅读(18)  评论(0)    收藏  举报