Migrating Data from one Database Table to Another
Note: The destination Table Schema should be the same as the source
def MigrateSourceTableToDestTable():
source_db = dbclass.Database(the_host=10.10.10.123,the_db='my_source_db')
dest_db = dbclass.Database(the_host=10.10.10.125, the_db='my_dest_db')
_the_table = 'table_to_migrate'
_qry = "SELECT * FROM {}.{}".format(source_db, the_table)
rows = source_db.GetUnbuffQryCursorObject(_qry)
for row in rows.fetchall_unbuffered():
col_val = iter(row)
next(col_val) # skip the id as dest will auto increment
_record = {
"`col_1`": str(next(col_val)),
"`col_2`": str(next(col_val)),
"`col_3`": str(next(col_val)),
"`col_4`": str(next(col_val)),
"`col_5`": str(next(col_val))
}
dest_db.InsertDictionaryValues(db_table=the_table, insert_dict=_record, verbose_print=True)
source_db.CloseConn()
dest_db.CloseConn()