Skip to content
Advertisement

Can I connect to mysql using Psycopg2 lib

I have a project in python that connects to a postgreSQL database.

That project have a module that connects to other data base. The connection string is on a configuration file. I configure it to use a mysql database like this:

database_url = mysql://user:password@localhost/database

One running the module I always get the following error:

line 179, in connect connection_factory=connection_factory, async=async) psycopg2.OperationalError: FATAL: password authentication failed for user “tmp” FATAL: password authentication failed for user “user”

I know that all the communication to the data base is made by the python ORM SQLAlchemy and that this ORM supports MySQL DBs.

I don’t known why I get a authentication error sent by the psycopg2 lib.

Advertisement

Answer

SQLAlchemy supports different dialects to connect to various databases with appropriate driver. Both MySQL and PostgreSQL are supported. You would use psycopg2 to connect to Postgres and e.g. MySQLdb to connect to MySQL. You also have to change the connection string.

See here for details: http://docs.sqlalchemy.org/en/latest/core/engines.html

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement