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 in Python by ana1504.k
• 7,890 points
25 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 by SDeb
• 13,210 points

Related Questions In Python

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
75 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
183 views
0 votes
1 answer

How to calculate time interval between two time strings in Python

Try doing this - It is efficient for ...READ MORE

answered Nov 29, 2018 in Python by Nymeria
• 3,520 points

edited Dec 11, 2018 by Nymeria 192 views
0 votes
1 answer

How to calculate cosine similarity between two lists using Pythong?

You should try SciPy. It has a bunch ...READ MORE

answered Dec 17, 2018 in Python by charlie_brown
• 7,720 points
1,527 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
• 56,960 points
4,108 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 in Python by rajesh
• 1,210 points
199 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
• 56,960 points
808 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,560 points
60 views
0 votes
1 answer

Connect to an URI in postgres

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

answered Jul 29 in Python by SDeb
• 13,210 points
69 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,210 points
344 views