MySQL批量修改表前缀
error_reporting(0); $old_pre = 'tdr_'; // 原表前缀 $new_pre = 'db_'; // 新表前缀 // 配置连接 $db = new mysqli('127.0.0.1', 'db_user', 'db_pass', 'db_name'); if ($db->connect_error) die('Connect Error (' . $db->connect_errno . ') ' . $db->connect_error); $query = $db->query('SHOW TABLES;'); $list = $query->fetch_all(); echo 'table : ', count($list),'<hr>'; $len = strlen($old_pre); foreach ($list as $val) { $new_name = $new_pre.substr($val[0], $len, strlen($val[0])-$len); echo "ALTER TABLE {$val[0]} RENAME {$new_name};<br />"; $db->query("ALTER TABLE {$val[0]} RENAME {$new_name};"); } echo '<hr>success.'; $db->close();