利用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编写通用脚本自动检查两个不同服务器的新旧数据库的表结构差异
问题:工作过程中,不管是什么项目,伴随着项目不断升级版本,对应的项目数据库业务版本也不断升级,数据库出现新增表.修改表.删除表.新增字段.修改字段.删除字段等变化,如果人工检查,数据库表和字段比较多的 ...
随机推荐
- Java基础学习笔记(三)
18.2.1无参无返回值的方法 18.2.1.1定义方法的语法格式 public static void 方法名称(){ 方法体 } 方法调用 类名.方法名称(); 注意:在Java中,同一个类中的方 ...
- 简单的jQ代码
简单的jQ代码 /* * Lazy Load - jQuery plugin for lazy loading images * * Copyright (c) 2007-2012 Mika Tuup ...
- 198. House Robber(Array; DP)
You are a professional robber planning to rob houses along a street. Each house has a certain amount ...
- Unity之Application.runInBackground = true
默认是False, 设置 Application.runInBackground = true; 则 void OnApplicationPause(bool pause) 不再起作用
- http://www.bugku.com:Bugku——Easy_vb
之前复习了汇编等知识,这是人生中第一个逆向题目,嘻嘻. 启程. 对于执行文件,首先需要看它是32位还是64位的.这里了解到静态工具IDA的启动程序为idaq.exe和idaq64.exe( ...
- [LeetCode_98]Validate Binary Search Tree
题目链接 https://leetcode.com/problems/validate-binary-search-tree/ 题意 判断给定树是否是BST 思路 根据定义判断.递归. 代码 clas ...
- django序列化单表的4种方法的介绍
这里主要是讲序列化单表的几种方法 先看下models中设计的表结构 from django.db import models # Create your models here. class Book ...
- swift - label字体 倾斜,加粗
/* label.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];//加粗 label.font = [UIFont ...
- shell中颜色的设置
linux启动后环境变量加载的顺序为:etc/profile → /etc/profile.d/*.sh → ~/.bash_profile → ~/.bashrc → [/etc/bashrc] 想 ...
- Inno Setup自定义安装界面脚本
; 脚本由 Inno Setup 脚本向导 生成! ; 有关创建 Inno Setup 脚本文件的详细资料请查阅帮助文档! #define MyAppName "RemoteCard&quo ...