园子看到使用MySQL对比数据库表结构,参考测试发现

mysql> use test;
create table test1
(id int not null primary key,
a varchar(10) not null,
b varchar(10),
c varchar(10) comment 'c',
d int
)
ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='test1';
create table test2
(id int not null ,
a varchar(10),
b varchar(5),
c varchar(10),
D int
)
ENGINE=myisam DEFAULT CHARSET=utf8 COMMENT='test2';
[root@localhost uest]# mysqldiff --server1=root:mysql5635@localhost:3306 --server2=root:mysql5635@localhost:3306 --changes-for=server2 --show-reverse --difftype=sql test.test1:test.test2
bash: mysqldiff: command not found
[root@localhost uest]#

搜索才知道mysqldiff工具是官方MySQL-Utilities工具集的一个脚本。mysqldiff用来比较对象的定义是否相同并显示不同的地方,mysqldiff 是通过对象名称来进行比较的。
系统环境紧接上一篇,因此需下载相应的rpm包

[root@localhost tools]# wget https://cdn.mysql.com//Downloads/MySQLGUITools/mysql-utilities-1.6.5-1.el6.noarch.rpm
[root@localhost tools]# rpm -ivh mysql-utilities-1.6.-.el6.noarch.rpm
warning: mysql-utilities-1.6.-.el6.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
mysql-connector-python >= 2.0. is needed by mysql-utilities-1.6.-.el6.noarch
[root@localhost tools]#

需要依赖文件

[root@localhost tools]# wget https://cdn.mysql.com//Downloads/Connector-Python/mysql-connector-python-2.1.5-1.el6.i686.rpm
[root@localhost tools]# rpm -ivh mysql-connector-python-2.1.-.el6.i686.rpm
warning: mysql-connector-python-2.1.-.el6.i686.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [%]
:mysql-connector-python ########################################### [%]
[root@localhost tools]# rpm -ivh mysql-utilities-1.6.-.el6.noarch.rpm
warning: mysql-utilities-1.6.-.el6.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ########################################### [%]
:mysql-utilities ########################################### [%]
[root@localhost tools]#

然后就可以执行mysqldiff命令了

[root@localhost tools]# mysqldiff --server1=root:mysql5635@localhost:3306 --server2=root:mysql5635@localhost:3306 --changes-for=server2 --skip-table-options --show-reverse --difftype=sql test.test1:test.test2
# WARNING: Using a password on the command line interface can be insecure.
# server1 on localhost: ... connected.
# server2 on localhost: ... connected.
# Comparing test.test1 to test.test2 [FAIL]
# Transformation for --changes-for=server2:
# ALTER TABLE `test`.`test2`
DROP COLUMN D,
ADD PRIMARY KEY(`id`),
CHANGE COLUMN b b varchar() NULL,
ADD COLUMN d int() NULL AFTER c,
CHANGE COLUMN a a varchar() NOT NULL,
CHANGE COLUMN c c varchar() NULL COMMENT 'c'; #
# Transformation for reverse changes (--changes-for=server1):
#
# ALTER TABLE `test`.`test1`
# DROP PRIMARY KEY,
# DROP COLUMN d,
# CHANGE COLUMN b b varchar() NULL,
# ADD COLUMN D int() NULL AFTER c,
# CHANGE COLUMN a a varchar() NULL,
# CHANGE COLUMN c c varchar() NULL;
# # Compare failed. One or more differences found.
[root@localhost tools]#

MySQL Utilities 提供一组命令行工具用于维护和管理 MySQL 服务器,可参考官方手册,或者查阅MySQL Utilities教程

MySQL-Utilities:mysqldiff的更多相关文章

  1. MySQL utilities介绍&出现 No module named utilities

    目录 安装 mysqlreplicate mysqlrplcheck mysqlrplshow mysqlrpladmin mysqlfailover mysqldbcompare 详细介绍 mysq ...

  2. MySQL Utilities管理工具

    前提: 1.安装MySQL Utilities工具 2.复制my_print_defaults命令至/usr/bin下或写入环境变量. 卸载方式: python ./setup.py clean -- ...

  3. (5.6)mysql高可用系列——MySQL Utilities 管理工具

    关键词:mysql工具集,mysql管理工具,mysql utilities [1]安装mysql utilities cd /download wget https://cdn.mysql.com/ ...

  4. MySQL Utilities工具教程

    一.MySQL Utilities介绍 MySQL Utilities 提供一组命令行工具用于维护和管理 MySQL 服务器,包括: 管理工具 (克隆.复制.比较.差异.导出.导入)复制工具 (安装. ...

  5. MySQL管理工具MySQL Utilities — 介绍与安装(1)

    MySQL Utilities介绍 MySQL Utilities 提供一组命令行工具用于维护和管理 MySQL 服务器,包括: 管理工具 (克隆.复制.比较.差异.导出.导入) 复制工具 (安装.配 ...

  6. Windows mysql提示:1045 access denied for user 'root'@'localhost' using password yes

    Windows mysql提示:1045 access denied for user 'root'@'localhost' using password yes http://blog.csdn.n ...

  7. MySQL错误:The user specified as a definer (XXX@XXX) does not exist

    今天由于更换服务器,重新再本地备份了数据库,试运行程序报错,如下: MySQL错误:The user specified as a definer (XXX@XXX) does not exist 意 ...

  8. MySQL内核:InnoDB存储引擎 卷1

    MySQL内核:InnoDB存储引擎卷1(MySQL领域Oracle ACE专家力作,众多MySQL Oracle ACE力捧,深入MySQL数据库内核源码分析,InnoDB内核开发与优化必备宝典) ...

  9. MySQL查询优化:查询慢原因和解决技巧

    在开发的朋友特别是和mysql有接触的朋友会碰到有时mysql查询很慢,当然我指的是大数据量百万千万级了,不是几十条了,下面我们来看看解决查询慢的办法. MySQL查询优化:查询慢原因和解决方法 会经 ...

随机推荐

  1. k8s 安装

    1.1 k8s的架构 除了核心组件,还有一些推荐的Add-ons: 组件名称 说明 kube-dns 负责为整个集群提供DNS服务 Ingress Controller 为服务提供外网入口 Heaps ...

  2. Astar伪代码

    while(OPEN!=NULL) { 从OPEN表中取估价值f最小的节点n; if(n节点==目标节点){ break; } for(当前节点n 的每个子节点X) { 算X的估价值; if(X in ...

  3. nginx下Thinkphp 隐藏index.php

    thinkphp config配置: 'URL_MODEL' => '2', //URL模式 nginx rewrite配置: location / { if (!-e $request_fil ...

  4. Python3简介

    Python3简介 Python 是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. Python 的设计具有很强的可读性,相比其他语言经常使用英文关键字,其他语言的一些标点符号,它具有 ...

  5. <scrapy爬虫>爬取quotes.toscrape.com

    1.创建scrapy项目 dos窗口输入: scrapy startproject quote cd quote 2.编写item.py文件(相当于编写模板,需要爬取的数据在这里定义) import ...

  6. 面试系列14 redis的过期策略都有哪些

    (1)设置过期时间 我们set key的时候,都可以给一个expire time,就是过期时间,指定这个key比如说只能存活1个小时?10分钟?这个很有用,我们自己可以指定缓存到期就失效. 如果假设你 ...

  7. Linux 实用指令(7)--Linux 磁盘分区、挂载

    目录 Linux 磁盘分区.挂载 1 分区基础知识 1.1 分区的方式: 1.2 windows 下的磁盘分区 2 Linux分区 2.1 原理分析 2.2 磁盘说明 2.3 使用lsblk指令查看当 ...

  8. opencv编译:opencv 3.4.1 编译 contrib模块,增加人脸识别

    start cmake-gui select the opencv source code folder and the folder where binaries will be built (th ...

  9. Leetcode148. Sort List排序链表

    在 O(n log n) 时间复杂度和常数级空间复杂度下,对链表进行排序. 示例 1: 输入: 4->2->1->3 输出: 1->2->3->4 示例 2: 输入 ...

  10. 2-sat——poj3678经典建图

    比较经典的建图,详见进阶指南 2-sat一般要用到tarjan来求强连通分量 /*2-sat要加的是具有强制关系的边*/ #include<iostream> #include<cs ...