首页 > 代码库 > MySQL Utilities
MySQL Utilities
园子看到使用MySQL对比数据库表结构,参考测试发现
[root@localhost uest]# mysqldiff --server1=dba:mysql5635@localhost --server2=dba:mysql5635@localhost --changes-for=server2 --show-reverse --difftype=sql test.test1:test.test2bash: 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.5-1.el6.noarch.rpmwarning: mysql-utilities-1.6.5-1.el6.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEYerror: Failed dependencies: mysql-connector-python >= 2.0.0 is needed by mysql-utilities-1.6.5-1.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.5-1.el6.i686.rpmwarning: mysql-connector-python-2.1.5-1.el6.i686.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEYPreparing... ########################################### [100%] 1:mysql-connector-python ########################################### [100%][root@localhost tools]# rpm -ivh mysql-utilities-1.6.5-1.el6.noarch.rpmwarning: mysql-utilities-1.6.5-1.el6.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEYPreparing... ########################################### [100%] 1:mysql-utilities ########################################### [100%][root@localhost tools]#
然后就可以执行mysqldiff命令了
[root@localhost tools]# mysqldiff --server1=dba:mysql5635@localhost --server2=dba:mysql5635@localhost --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(10) NULL, ADD COLUMN d int(11) NULL AFTER c, CHANGE COLUMN a a varchar(10) NOT NULL, CHANGE COLUMN c c varchar(10) 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(5) NULL, # ADD COLUMN D int(11) NULL AFTER c, # CHANGE COLUMN a a varchar(10) NULL, # CHANGE COLUMN c c varchar(10) NULL;## Compare failed. One or more differences found.[root@localhost tools]#
MySQL Utilities 提供一组命令行工具用于维护和管理 MySQL 服务器,可参考官方手册,或者查阅MySQL Utilities教程。
MySQL Utilities
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。