验证oracle数据与mysql数据同步的一致性

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

背景

在之前搭建了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=<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值