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,910 points
342 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,300 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, 2020 in Python by Gitika
• 65,910 points
2,035 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, 2020 in Python by Niroj
• 82,880 points
1,623 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
556 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,560 points
1,537 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
• 58,090 points
19,662 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,270 points
1,592 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
• 58,090 points
5,402 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,810 points
486 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,300 points
2,430 views
0 votes
1 answer

How to convert string into epoch time?

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

answered Sep 22, 2018 in Python by SDeb
• 13,300 points
6,212 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP