<?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. metasploit framework(十五):弱点扫描

    openvas扫描生成NBE格式的日志 改个比较好记的文件名 将日志导入到msf进行后续操作,导入之前查看一下hosts和services 导入nbe格式的文件 查看漏洞弱点 msf直接调用nessu ...

  2. 【pycharm】使用过程的相关问题

    背景:安装scrapy后在cmd里可以正常import scrapy模块,但是在pycharm里不可以(python2.7) 问题:cmd中能正常导入模块,在pycharm报错 原因:pycharm里 ...

  3. pta6-17(另类堆栈)

    题目链接:https://pintia.cn/problem-sets/1101307589335527424/problems/1101313244872126464 题意:一种新的堆栈,用Top表 ...

  4. Spyder启动黑屏,终端显示QOpenGLShaderProgram::uniformLocation(qt_Matrix): shader program is not linked QOpenG

    cd /etc/ld.so.conf.d目录中有 i386-linux-gnu_GL.conf and x86_64-linux-gnu_GL.conf等文件cat x86_64-linux-gnu_ ...

  5. Dbutils 的JDBC链接

    最近实践周,再次用到了这个Apache的开源工具包就在次对着个方面进行了复习 1.JDBC的基本 操作姿势 2.JDBC的步骤是 1.添加驱动包 Class.forName("oracle. ...

  6. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  7. TZOJ 1705 Dining(拆点最大流)

    描述 Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she wil ...

  8. xadmin系列之单实例模式

    先看下单实例的定义 python的模块实现单例模式是python语言特有的,python的模块天然就是单例的,因为python有个pyc文件,导入一次后,第二次导入直接从pyc中取数据了 这里我们主要 ...

  9. width多少,超过了用....表示

    maxWidth:'140px',whiteSpace:'nowrap',overflow:'hidden',textOverflow:'ellipsis'

  10. Linux磁盘挂载详述

    1.查看硬盘信息及分区 一般使用”fdisk -l”命令可以列出系统中当前连接的硬盘,设备和分区信息.新硬盘没有分区信息,则只显示硬盘大小信息. [root@localhost home]# fdis ...