dbstructsync 多套mysql环境表、字段、索引的差异sql产出(原创)

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

dbstructsync 多套mysql环境表、字段、索引的差异sql产出(原创)

yingchen   2019-11-24 我要评论

最近写了一个工具(比较两套测试环境数据库表、表字段、索引的差异)

功能:可以比较两套环境中mysql指定库中表、表字段及索引的差异,返回具体需要同步的执行sql 

A环境的数据库db 作为sourcedb, B环境的数据库db targetdb ,代码比较的是 sourcedb 与targetdb 的差异,执行完sql后,保证了sourcedb 包含于targetdb 

结果包括新建表sql,修改、增加字段sql, 删除、新增索引sql 

具体使用方法:

pip install  -i http://pypi.python.org/pypi  dbstructsync   

在代码里引入使用, from DbStructSync import cli 

# result=cli.db_sync(sourcedb, targetdb) ,sourcedb,targetdb是两个dict的参数,具体参数看下面
# sourcedb = {'host':'10.1.1.31','port':33306,'user':'roo1','passwd':'roo2','db':'investment'},
# targetdb = {'host': '10.1.1.32', 'port': 33306, 'user': 'roo1', 'passwd': 'roo2', 'db': 'investment'}
# )

result是一个list,包含sourcedb 与targetdb中不一致的地方,需要将这些语句在targetdb中执行,从而保证两个环境中的结构一致

同时还支持 cli.db_sync_commandline  操作,代码写入到aa.py代码中

result = cli.db_sync_commandline()

python aa.py --source  host=10.1.1.32,port=33306,user=root,passwd=root,db=investment --target host=10.1.1.37,port=33306,user=root,passwd=root,db=investment

python x.py --only-index  --only-fields --source  xx  --target xx 其中 --source , --target是必须的参数

 [--only-index] [--only-fields] 只对索引比较,只对字段比较的配置,最终结果也只包含对应的配置项内容

 

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们