php批量轉換Mysql表引擎

來源:互聯網
上載者:User
<?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";    }}
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.