PHP 일괄 변환 Mysql 테이블 엔진

巴扎黑
풀어 주다: 2016-11-24 10:28:20
원래의
1166명이 탐색했습니다.

<?php
/**
 * 批量转换Mysql表引擎
 */
error_reporting(E_ALL);
// 数据库连接配置
$host     = &#39;localhost&#39;;
$username = &#39;root&#39;;
$passwd   = &#39;&#39;;
$database = &#39;test&#39;;
// 要转换的库名配置,多库转换增加配置元素即可
$configs  = array($database);
// 转换配置
$convert_rule = array(
    &#39;from&#39; => &#39;InnoDB&#39;,
    &#39;to&#39;   => &#39;MyISAM&#39;
);
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(&#39;Not found db: &#39;. $db_name);
            $tables = mysql_query("SHOW FULL TABLES");
            while ($table = mysql_fetch_row($tables))
            {
                if ($table[1] === &#39;VIEW&#39;) continue;
                $sql = "SHOW TABLE STATUS from {$db_name} where Name=&#39;{$table[0]}&#39; ";
                if ($result = mysql_query($sql))
                {
                    $table_status = mysql_fetch_row($result);
                    
                    if (strtolower($table_status[1]) == strtolower($convert_rule[&#39;from&#39;]))
                        mysql_query("ALTER TABLE {$table[0]} ENGINE = {$convert_rule[&#39;to&#39;]}");
                }
            }
            echo $db_name,&#39;:All tables ENGINE is &#39;,$convert_rule[&#39;to&#39;],"\n";
        }
        
    } else {
        echo "db error\n";
    }
}
로그인 후 복사


원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!