<?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. LINUX 设置 backspace为删除键

    描述 :在linux/unix平台上的 sqlplus中,如果输错了字符,要想删除,习惯性的按下backspace键后,发现非但没有删除想要删掉的字符,还多出了两个字符^H. 原因:由于终端默认ctr ...

  2. 命令行执行jenkins,构建job(可传递参数)

    背景| 组内做UI测试,需要每天晚上执行一遍jenkins任务,jenkins任务本身是参数化构建的.但是因为jenkins本身的定时执行没有办法指定特殊的参数,所以考虑使用命令行方式启动jenkin ...

  3. openvpn 使用账户密码认证

    OpenVPN使用user/passwd完成验证登录 OpenVPN使用user/passwd完成验证登录1,为什么要使用user/passwd?比常规openvpn管理方便,删除用户只需要在pwd. ...

  4. PHP从规定字符中生成固定位数随即串

               }

  5. empty 与 remove 的区别

    empty()移除指定元素中的所有子节点,拿$("p").empty()来说,他只是把<p>dsfsd</p>中的文本给移除了,而留下 了<p> ...

  6. 数位dp poj1850

    题目链接:https://vjudge.net/problem/POJ-1850 这题我用的是数位dp,刚刚看了一下别人用排列组合,我脑子不行,想不出来. 在这题里面我把a看成1,其他的依次递增,如果 ...

  7. leetcode输入输出加速

    C++兼容C的输入输出,即cin与scanf混用文件指针不会出错,cout亦同,导致cin有额外开销. 可以用std::ios::sync_with_stdio(false);手动关闭. cin.ti ...

  8. 26【python】sprintf风格的字符串

    参考资料:https://docs.python.org/3.5/library/stdtypes.html#old-string-formatting 实例 s#!/bin/python a = ( ...

  9. TZOJ 3710 修路问题(最小差值生成树kruskal或者LCT)

    描述 xxx国“山头乡”有n个村子,政府准备修建乡村公路,由于地形复杂,有些乡村之间可能无法修筑公路,因此政府经过仔细的考察,终于得到了所有可能的修路费用数据.并将其公布于众,广泛征求村民的修路意见. ...

  10. 将unitest整合和python发送测试报告

    废话少说先上代码 # -*- coding:UTF-8 -*- __autor__ = 'zhouli' __date__ = '2018/11/12 21:29' import unittest i ...