对比MySQL不同环境下的表结构。

  • 安装mysql-connector-python
1
brew cask install mysql-connector-python
  • 安装mysql-utilities
1
brew cask install mysql-utilities
  • 安装mysql_config_editor
1
brew cask install mysql_config_editor
  • 配置信息
1
mysql_config_editor set --login-path=name --host=host --port=port --user=user --password

要对比至少需要源信息和目标信息

  • 移除信息
1
mysql_config_editor remove --login-path=name --host=host --port=port --user=user --password
  • 查看所有
1
mysql_config_editor print --all
  • Usage
1
Usage: mysqldiff --server1=user:pass@host:port:socket --server2=user:pass@host:port:socket db1.object1:db2.object1 db3:db4
  • 相同
1
2
3
4
5
$ mysqldiff --server1=dev5 --server2=uat --difftype=sql profile.profile_note:profile.profile_note
# server1 on l-ars5.dev.ep.cn0.sgrl.io: ... connected.
# server2 on l-arsdb1.uat.op.tx3.sgrl.io: ... connected.
# Comparing profile.profile_note to profile.profile_note [PASS]
# Success. All objects are the same.
  • 不同
1
2
3
4
5
6
$ mysqldiff --server1=dev5 --server2=uat --difftype=sql profile.profile_note:profile.profile_note
# server1 on l-ars5.dev.ep.cn0.sgrl.io: ... connected.
# server2 on l-arsdb1.uat.op.tx3.sgrl.io: ... connected.
# Comparing profile.profile_note to profile.profile_note [FAIL]
# Transformation for --changes-for=server1:
#

注意: --port and --socket options are supported for the set/remove commands as of MySQL 5.6.11

参考: