<?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-两个库表结构差异比较的更多相关文章

  1. 利用PHP脚本辅助MySQL数据库管理5-检查异常数据

    <?php $dbi = new DbMysql; $dbi->dbh = 'mysql://root:mysql@127.0.0.1/coffeetest'; $map = array( ...

  2. 利用PHP脚本辅助MySQL数据库管理3-删除重复表索引

    <?php $dbi = new DbMysql; $dbi->dbh = 'mysql://root:mysql@127.0.0.1/coffeetest'; $map = array( ...

  3. 利用PHP脚本辅助MySQL数据库管理2-表主键表索引

    <?php $dbi = new DbMysql; $dbi->dbh = 'mysql://root:mysql@127.0.0.1/coffeetest'; $map = array( ...

  4. 利用PHP脚本辅助MySQL数据库管理1-表结构

    <?php $dbi = new DbMysql; $dbi->dbh = 'mysql://root:mysql@127.0.0.1/coffeetest'; $map = array( ...

  5. 创建MySQL用户 赋予某指定库表的权限 flush privileges才能生效!!!!;@'localhost'授权本地,@'%'授权远程

    update ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value 建议使用GRANT语句进行授权,语句如下: gra ...

  6. 创建MySQL用户 赋予某指定库表的权限

    摘自: http://renxiangzyq.iteye.com/blog/763837 update ERROR 1364 (HY000): Field 'ssl_cipher' doesn't h ...

  7. 利用Shell脚本将MySQL表中的数据转化为json格式

    脚本如下: #!/bin/bash mysql -s -phello test >.log <<EOF desc t1; EOF lines="concat_ws(',', ...

  8. MySQL:比较两个数据表不同部分

    简单比较 1.SELECT * FROM t2 WHERE id NOT IN (SELECT id FROM t1); 2.SELECT * FROM t2 WHERE NOT EXISTS(SEL ...

  9. sql server编写通用脚本自动检查两个不同服务器的新旧数据库的表结构差异

    问题:工作过程中,不管是什么项目,伴随着项目不断升级版本,对应的项目数据库业务版本也不断升级,数据库出现新增表.修改表.删除表.新增字段.修改字段.删除字段等变化,如果人工检查,数据库表和字段比较多的 ...

随机推荐

  1. Python基础之列表及元组的增删改查

    定义一个列表 晚上的状态不太适合写博客,容易犯困~ 列表的增加有三种方式 第一种主流的增加 append函数 list1 = ['noevil', 'fordearme', 'city', 'cust ...

  2. python--第四天总结

    lambda表达式 处理简单函数自动返回 学习条件运算时,对于简单的 if else 语句,可以使用三元运算来表示,即: # 普通条件语句 if 1 == 1: name = 'wupeiqi' el ...

  3. CentOS 删除文件的常用命令

    NO1. 删除当前目录的文件[root@rehat root]# rm test.txt NO2. 强制删除当前目录的文件,不弹出提示[root@rehat root]# rm -f test.txt ...

  4. no module named cv2

    运行python脚本时报错: ImportError: No module named cv2 第一想法: 使用命令: pip install cv2 会报错找不到请求的版本 解决方法: 使用命令 p ...

  5. Python+Selenium学习--设置等待时间

    场景 sleep():设置固定休眠时间.python 的time 包提供了休眠方法sleep() ,导入time 包后就可以使用sleep()进行脚本的执行过程进行休眠.implicitly_wait ...

  6. 通达OA 自定义菜单

    1.首先在系统管理----菜单设置中添加菜单主分类,菜单的图片默认是在D:\MYOA\webroot\images中.2.然后再编辑该菜单的下一级,增加子菜单项,子菜单的路径就是您要设置的网址.3.最 ...

  7. PHP: PCRE 函数- Manual

    1.函数 http://php.net/manual/zh/ref.pcre.php 2.语法 http://www.runoob.com/regexp/regexp-tutorial.html

  8. 模拟点击事件在alert前不起作用

    本来想在ajax提交前点击一下模态框,直到返回处理之前都显示正在保存,发现如标题的现象,几经折腾没找到解决办法,发现可能是 alert线程阻塞(冒泡)引起的,也没找到解决办法,于是借助第三方插件lay ...

  9. iOS - 抖音效果

    抖音的转场动画—iOS https://www.jianshu.com/p/29b0165de712 抖音的上下滑实现—iOS https://www.jianshu.com/p/e8799510c7 ...

  10. DBCO

    实现SAP连接外部数据库 也可用SM30维护DBCON的内容 SAP提供了对原生sql的操作,主要有以下几个类组成: CL_SQL_STATEMENT - Execution of SQL State ...