Connect to two databases

0 votes

I am trying to connect to two databases using Python and, also, use tables from both of the databases. How can I do this? Is the following code correct?

con = mdb.connect(host=MY_HOST, user=MY_USER, passwd=MY_PASS, db1=MY_DB1, db2=MY_DB2)
Jul 17, 2019 in Python by ana1504.k
• 7,890 points
63 views

1 answer to this question.

0 votes

If you don't specify the database in your connect call, you can write queries against multiple databases at once. 

db = _mysql.connect('localhost', 'user', 'passwd')

then

SELECT u.*, i.* FROM db1.users u LEFT JOIN db2.items i ON u.id = i.user_id
answered Jul 17, 2019 by SDeb
• 13,250 points

Related Questions In Python

0 votes
1 answer

I would like to connect to multiple databases in oracle

Hey Radhika, To communicate any database with Python ...READ MORE

answered Feb 17 in Python by Gitika
• 37,660 points
469 views
0 votes
1 answer

How do I sync the two models to two databases?

Hello @kartik, To sync the two models to ...READ MORE

answered Jun 29 in Python by Niroj
• 59,560 points
80 views
0 votes
1 answer

Connect to a MySQL DB in python?

db = MySQLdb.connect(host="localhost", # ...READ MORE

answered Jul 20, 2018 in Python by Nietzsche's daemon
• 4,260 points
113 views
0 votes
1 answer

Question on PyQt: How to connect a signal to a slot to start a background operation in Python

It shouldn't matter whether the connection is ...READ MORE

answered Nov 27, 2018 in Python by Nymeria
• 3,520 points
568 views
0 votes
1 answer

ProgrammingError: not all arguments converted during string formatting

Sorted!!!! just found the solution, 1 - apparently ...READ MORE

answered Sep 10, 2018 in Python by Priyaj
• 57,660 points
9,588 views
0 votes
2 answers

How do I connect to a MySQL Database in Python?

connect mysql database with python import MySQLdb db = ...READ MORE

answered Mar 28, 2019 in Python by rajesh
• 1,230 points
523 views
0 votes
1 answer

ProgrammingError: not all arguments converted during string formatting

Sorted!!!! just found the solution, 1 - apparently ...READ MORE

answered Sep 20, 2018 in Python by Priyaj
• 57,660 points
2,562 views
0 votes
1 answer

Connect to a MySQL using Python?

Very similar to mysqldb but better than ...READ MORE

answered Nov 16, 2018 in Python by Jino
• 5,770 points
119 views
0 votes
1 answer

Connect to an URI in postgres

The connection string passed to psycopg2.connect is ...READ MORE

answered Jul 29, 2019 in Python by SDeb
• 13,250 points
457 views
0 votes
1 answer

How to convert string into epoch time?

you are passing the parsed datetime object to ...READ MORE

answered Sep 21, 2018 in Python by SDeb
• 13,250 points
2,265 views