园子看到使用MySQL对比数据库表结构,参考测试发现
[[email protected] uest]# mysqldiff --server1=dba:[email protected] --server2=dba:[email protected] --changes-for=server2 --show-reverse --difftype=sql test.test1:test.test2 bash: mysqldiff: command not found [[email protected] uest]#
搜索才知道mysqldiff工具是官方mysql-utilities工具集的一个脚本。mysqldiff用来比较对象的定义是否相同并显示不同的地方,mysqldiff 是通过对象名称来进行比较的。
系统环境紧接上一篇,因此需下载相应的rpm包
[[email protected] tools]# wget https://cdn.mysql.com//Downloads/MySQLGUITools/mysql-utilities-1.6.5-1.el6.noarch.rpm [[email protected] tools]# rpm -ivh mysql-utilities-1.6.5-1.el6.noarch.rpm warning: mysql-utilities-1.6.5-1.el6.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY error: Failed dependencies: mysql-connector-python >= 2.0.0 is needed by mysql-utilities-1.6.5-1.el6.noarch [[email protected] tools]#
需要依赖文件
[[email protected] tools]# wget https://cdn.mysql.com//Downloads/Connector-Python/mysql-connector-python-2.1.5-1.el6.i686.rpm [[email protected] tools]# rpm -ivh mysql-connector-python-2.1.5-1.el6.i686.rpm warning: mysql-connector-python-2.1.5-1.el6.i686.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ########################################### [100%] 1:mysql-connector-python ########################################### [100%] [[email protected] tools]# rpm -ivh mysql-utilities-1.6.5-1.el6.noarch.rpm warning: mysql-utilities-1.6.5-1.el6.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ########################################### [100%] 1:mysql-utilities ########################################### [100%] [[email protected] tools]#
然后就可以执行mysqldiff命令了
[[email protected] tools]# mysqldiff --server1=dba:[email protected] --server2=dba:[email protected] --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. [[email protected] tools]#
MySQL Utilities 提供一组命令行工具用于维护和管理 MySQL 服务器,可参考官方手册,或者查阅MySQL Utilities教程。
时间: 2024-10-27 00:22:33