背景
在之前搭建了databus 用于oracle数据同步到mysql,同时也用了otter+canal 用于mysql数据同步到oracle,之前也写过监控databus和验证数据的脚本,但也只是验证,真正邮件收到不一致的数据后需要来做修复。所以验证数据的脚本产生了。
思路
产生不一致的数据无非是mysql端或oracle端或多或少数据,我们只按照id来进行比对就好(每5000个id对比一次),通过set去重,最终结果输出到文本中。
代码
读取配制文件中的表名,将查到的结果存入set,用mysql oracle两个结果集的差值得到其或多或少的id。
import pymysql
import cx_Oracle
def readTableName(filename,ouser,opword,odb,muser,mpword,hostname,mdb):
with open(filename,'r') as f:
for fcon in f.readlines():
fc = fcon.strip().strip('\n')
# escape startswith # line
if fc.startswith('#'):
continue
elif fc == "" or fc is None:
continue
else:
#execute sql
try:
#pdb.set_trace()
info = 'table_name:{:30} '.format(fc)
writeFile(info)
resstr='mysql has {} and oracle has {} '
#table_name add prifix
owner = 'tc'
# start with t owner = tc else kc
if not fc.startswith('t'):
owner='kc'

本文介绍了如何验证Oracle数据库与MySQL数据库在数据同步后的一致性。通过比较两个数据库中相同ID的数量,利用集合操作找出不一致的记录,并将结果输出到文本文件中。文章提供了实现此功能的思路及代码示例。
最低0.47元/天 解锁文章

4629

被折叠的 条评论
为什么被折叠?



