有些时候可能需要批量转换mysql表的引擎,如下为php操作实现
/**
* 批量转换mysql表引擎
*/
error_reporting(e_all);
// 数据库连接配置
$host = 'localhost';
$username = 'root';
$passwd = '';
$database = 'test';
// 要转换的库名配置,多库转换增加配置元素即可
$configs = array($database);
// 转换配置
$convert_rule = array(
'from' => 'innodb',
'to' => 'myisam'
);
mysql_engine_convert();
/**
* 转换函数
*/
function mysql_engine_convert()
{
global $host,$username,$passwd,$configs,$convert_rule;
if ( ($conn = mysql_connect($host, $username, $passwd)) !== false)
{
foreach ($configs as $db_name)
{
mysql_select_db($db_name) or exit('not found db: '. $db_name);
$tables = mysql_query("show full tables");
while ($table = mysql_fetch_row($tables))
{
if ($table[1] === 'view') continue;
$sql = "show table status from {$db_name} where name='{$table[0]}' ";
if ($result = mysql_query($sql))
{
$table_status = mysql_fetch_row($result);
if (strtolower($table_status[1]) == strtolower($convert_rule['from']))
mysql_query("alter table {$table[0]} engine = {$convert_rule['to']}");
}
}
echo $db_name,':all tables engine is ',$convert_rule['to'],"\n";
}
} else {
echo "db error\n";
}
} 本文链接http://www.cxybl.com/html/wlbc/Php/20120607/28510.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools