• 技术文章 >php教程 >php手册

    mysql 修改表引擎:php批量转换mysql表引擎

    2016-06-21 08:51:36原创558
    有些时候可能需要批量转换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



    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:mysql convert table name tables
    上一篇:平衡二叉树:php实现平衡二叉树(avl树) 下一篇:Z-Blog分类标签全站静态化方案
    PHP编程就业班

    相关文章推荐

    • 实例(Smarty+FCKeditor新闻系统)• Codeigniter检测表单post数据的方法,codeigniterpost• [PHP]set_time_limit — 设置脚本最大执行时间• SSI使用详解(二)• php mysql 数据库类

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网