0

I have two databases, one is located in localhost, the other one in located in another server.

In python, I want to import some data from database 2 to database 1:

  con1 = mdb.connect (host= xx, user=xx, passwd= xx, db= xx) //connect database 1
  cur1 = con1.cursor()
  con2 = mdb.connect (host= xx, user=xx, passwd= xx, db= xx) //connect database 2
  cur2 = con2.cursor()

  query = "update database1.table1 set area = (select database2.table2.area from database2.table2)"

  cur(1 or 2?).execute(query) //Don't know how to solve this problem

1 Answer 1

1

No, you can't do cross-server operations like that.

  1. Fetch your data from source database (in batches, if it's big)

  2. Prepare and send update statements to target database.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your information. But if the case is, two databases are located in the same server. How can I connect to them, and import some data from one to another?
if both databases are located in the same db process, it's quite easy. Something like insert into db1.table1 (col1, col2) select col1, col2 from db2.table2;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.