数据迁移之后需要做的是数据校正,这里使用python+数据库模块实现
- 连接数据库
- PG
- psycopg2
- MSSQL
- pymssql,已停止维护
- pyodbc
- 使用pandas读取
- read_sql
- 比较两个dataframe是否相等
- assert_frame_equal
- 代码
import psycopg2import pyodbcimport pandas as pdfrom pandas.testing import assert_frame_equal## read pg dataconn1 = psycopg2.connect(database='cm_test', user='postgres',password='123456', host='localhost', port='5432')df1 = pd.read_sql('select * from account_category',conn1)df1.columns = list(range(df1.shape[1]))# print(df1)## read mssql dataconn2 = pyodbc.connect('DRIVER={SQL Server};SERVER=localhost;DATABASE=CM_BE;UID=sa;PWD=123456')df2 = pd.read_sql('select * from AccountCategory_LU',conn2)df2.columns = list(range(df2.shape[1]))# print(df2)## compare data from two databasesassert_frame_equal(df1, df2)