I have a question, I hope you can help.
I have 2 MySQL servers. I have a Python job which extracts certain data from one server and dumps it into the other, periodically.
This is super slow; it's taking a lifetime to make the copy.
Can anyone help me to make it faster?
import mysql.connector
import pandas as pd
from sqlalchemy import create_engine
import multiprocessing as mp
from multiprocessing import cpu_count
try:
engine_source = create_engine("connection string")
iconn = engine_source.connect()
data = pd.read_sql('SELECT QUERY ', iconn)
data['load_id'] = '2'
print('EXTRACT COMPLETE')
engine_dest = create_engine("connection string 2")
iconndest = engine_dest.connect()
print(iconndest)
data.to_sql(schema ='dbname', name='tablename', con=iconndest, if_exists = 'append', chunksize=1000, index= False)
engine_source.dispose()
engine_dest.dispose()
except Exception as e:
print('extract: ' + str(e))