There are 2 machines
server = 192.168.10.10
slave = 192.168.10.100
they have data base named test1 also have same tables
I want to select all from a table(base2)
on a database(test1)
on server and drop the same table(base2)
on slave and insert all data to it every X min .
conMaster = pymysql.connect(host=masterIp1, user=masterUser1, password=masterPass1,
database=dataBase1)
conSlave = pymysql.connect(host=slaveIp1, user=slaveUser1, password=slavePass1, database=dataBase1)
curMaster = conMaster.cursor()
curSlave = conSlave.cursor()
#consider we know the table name and in both servers table name is base2
masterData=curMaster.execute("select * from base2")
SlaveData=curSlave.execute("select * from base2")
#if base2 on master server has 10 more rows than slave master
#consider database name is test1 in both servers
if len(masterData)>len(SlaveData)+10:
curSlave.execute("drop table base2"
"create table test1.base2"
"insert test1.base2"
"select * from ??"
)
since cur.slave.execute
references to slave server, when I want to select * from base2
on master server I don't know how to write the code.
question from:
https://stackoverflow.com/questions/65829254/select-from-one-machine-insert-to-another 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…