利用PHP脚本辅助MySQL数据库管理4-两个库表结构差异比较
<?php
define('DATABASE1', 'coffeetest');
$dbi1 = new DbMysql;
$dbi1->dbh = 'mysql://root:mysql@127.0.0.1/'.DATABASE1; define('DATABASE2', 'sinatest');
$dbi2 = new DbMysql;
$dbi2->dbh = 'mysql://root:mysql@127.0.0.1/'.DATABASE2; // db1
$db1 = array();
$map = array();
$dbi1->fetchMap("SHOW TABLES", $map);
$tables = array_keys($map);
for($i=0; $i<count($tables); $i++){
$map = array();
$dbi1->fetchMap("DESCRIBE ".$tables[$i], $map);
$structures = array();
foreach($map as $k=>$v){
$structures[] = "$k=$v";
}
$db1[$tables[$i]] = $structures;
} // db2
$db2 = array();
$map = array();
$dbi2->fetchMap("SHOW TABLES", $map);
$tables = array_keys($map);
for($i=0; $i<count($tables); $i++){
$map = array();
$dbi2->fetchMap("DESCRIBE ".$tables[$i], $map);
$structures = array();
foreach($map as $k=>$v){
$structures[] = "$k=$v";
}
$db2[$tables[$i]] = $structures;
} // db1 compare db2
echo("***** ".DATABASE1." *****\n");
foreach($db2 as $table=>$structures2){
$structures1 = $db1[$table];
if(empty($structures1)) {
echo(".$table not exist\n");
continue;
}
for($i=0; $i<count($structures2); $i++){
if(1==1 && !in_array($structures2[$i], $structures1))
echo $table.".".$structures2[$i]."\n";
}
} // db2 compare db1
echo("***** ".DATABASE2." *****\n");
foreach($db1 as $table=>$structures1){
$structures2 = $db2[$table];
if(empty($structures2)) {
echo(DATABASE2.".$table not exist\n");
continue;
}
for($i=0; $i<count($structures1); $i++){
if(1==0 && !in_array($structures1[$i], $structures2))
echo $table.".".$structures1[$i]."\n";
}
}
?>
利用PHP脚本辅助MySQL数据库管理4-两个库表结构差异比较的更多相关文章
- 利用PHP脚本辅助MySQL数据库管理5-检查异常数据
<?php $dbi = new DbMysql; $dbi->dbh = 'mysql://root:mysql@127.0.0.1/coffeetest'; $map = array( ...
- 利用PHP脚本辅助MySQL数据库管理3-删除重复表索引
<?php $dbi = new DbMysql; $dbi->dbh = 'mysql://root:mysql@127.0.0.1/coffeetest'; $map = array( ...
- 利用PHP脚本辅助MySQL数据库管理2-表主键表索引
<?php $dbi = new DbMysql; $dbi->dbh = 'mysql://root:mysql@127.0.0.1/coffeetest'; $map = array( ...
- 利用PHP脚本辅助MySQL数据库管理1-表结构
<?php $dbi = new DbMysql; $dbi->dbh = 'mysql://root:mysql@127.0.0.1/coffeetest'; $map = array( ...
- 创建MySQL用户 赋予某指定库表的权限 flush privileges才能生效!!!!;@'localhost'授权本地,@'%'授权远程
update ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value 建议使用GRANT语句进行授权,语句如下: gra ...
- 创建MySQL用户 赋予某指定库表的权限
摘自: http://renxiangzyq.iteye.com/blog/763837 update ERROR 1364 (HY000): Field 'ssl_cipher' doesn't h ...
- 利用Shell脚本将MySQL表中的数据转化为json格式
脚本如下: #!/bin/bash mysql -s -phello test >.log <<EOF desc t1; EOF lines="concat_ws(',', ...
- MySQL:比较两个数据表不同部分
简单比较 1.SELECT * FROM t2 WHERE id NOT IN (SELECT id FROM t1); 2.SELECT * FROM t2 WHERE NOT EXISTS(SEL ...
- sql server编写通用脚本自动检查两个不同服务器的新旧数据库的表结构差异
问题:工作过程中,不管是什么项目,伴随着项目不断升级版本,对应的项目数据库业务版本也不断升级,数据库出现新增表.修改表.删除表.新增字段.修改字段.删除字段等变化,如果人工检查,数据库表和字段比较多的 ...
随机推荐
- 开启swap交换分区
开启swap 1.创建用于交换分区的文件: dd if=/dev/zero of=/mnt/swap bs=1M count=2048 注:block_size.number_of_block 大小可 ...
- 搭建php渗透测试环境
php服务器下载地址 http://vdisk.weibo.com/s/D9I4jIIfNddvh 在C盘下创建一个www文件夹 安装phpstudy 下一步安装 修改配置文件 将端口改成8080 保 ...
- contextlib 上下文管理器
在Python中,读写文件这样的资源要特别注意,必须在使用完毕后正确关闭它们.正确关闭文件资源的一个方法是使用try...finally: try: f = open('/path/to/file', ...
- app和wap手机网站的区别在哪里
第一点 我们从依附的平台来看: 移动Wap网站:由移动设备的浏览器来支持,只要移动设备支持上网浏览网站基本上可以随时随地的打开网站查找自己需要的信息. 移动App客户端:由智能移动设备的操作系统来支持 ...
- codeblocks安装(自带gcc编译器)
下载安装自带c编译器的的codeblocks. 网址:http://www.codeblocks.org/downloads/26 自带gcc编译器的版本 codeblocks-16.01mingw- ...
- python读写文件中read()、readline()和readlines()的用法
python中有三种读取文件的函数: read() readline() readlines() 然而它们的区别是什么呢,在平时用到时总会遇到,今天总结一下. 0. 前期工作 首先新建一个文件read ...
- PAT1135(红黑书的判定)
There is a kind of balanced binary search tree named red-black tree in the data structure. It has th ...
- Android 支付宝/微信支付结果判断
微信支付结果码 private static final int PAY_OK = 0; //交易成功 private static final int PAY_ERR = -1; //交易失败 pr ...
- phpStudy安装教程
1.在phpStudy官网下载安装包(http://phpstudy.php.cn/)2.解压安装后,若提示没有“VC9.VC11.VC14运行库,注意是X86 32位”,则在phpStudy下载对应 ...
- .linearDrag on rigidbody / rigidbody2D in code?
it's rigidbody.drag not .linearDrag 这几天在做一个弹球的游戏,发现小球落下后不会自动停,测试后发现线性阻尼增加后可以 于是加了个触发器不停增加线性阻尼值 priva ...