php mysql 复制数据库表结构图,php – 在MySQL中复制数据库,如何复制视图?

尝试使用在

MySQL服务器上运行SQL查询的

PHP脚本将数据库复制到新数据库中.我所熟悉的代码是:

$dbh->exec("CREATE DATABASE IF NOT EXISTS $new_news CHARACTER SET UTF8;");

$results = $dbh->query("SHOW TABLES FROM $old_news");

$table_list = $results->fetchAll(PDO::FETCH_NUM);

foreach($table_list as $table_row){

foreach($table_row as $table){

$results = $dbh->query("SELECT table_type FROM information_schema.tables where table_schema = '$old_news' and table_name = '$table'");

$table_type = $results->fetch(PDO::FETCH_ASSOC);

$table_type = $table_type['table_type'];

if($table_type == 'BASE TABLE'){

echo "Creating table $table and populating...\n";

$dbh->exec("CREATE TABLE $new_news.$table LIKE $old_news.$table");

$dbh->exec("INSERT INTO $new_news.$table SELECT * FROM $old_news.$table");

}else if($table_type == 'VIEW'){

//echo "Creating view $table...\n";

//$dbh->exec("CREATE VIEW $new_news.$table LIKE $old_news.$table");

echo "$table is a view, which cannot be copied atm\n";

}else{

echo "Skipping $table_type $table, unsupported type\n";

}

}

}

这当前查看$old_news中的所有表,在information_schema中查找表类型,并根据类型在$new_news中创建相同的表.对于表,它创建表结构相同,然后’INSERT INTO SELECT’来填充它们.

如何在没有mysqldump的情况下复制整个数据库的视图?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值