Jakub M.
Jakub M.

Reputation: 33827

sqlalchemy: connect to MySQL without password

I have MySQL base "test" with no password on root. I can log in there

mysql -uroot test # all fine

I want to access it with sqlalchemy. I try with those URLs:

mysql+mysqldb://root@localhost/test

mysql+mysqldb://root:@localhost/test

But both of them fail with error:

sqlalchemy.exc.OperationalError: (OperationalError)
    (1045, "Access denied for user
    'root'@'localhost' (using password: NO)") None None

How should I access the base without a password?

Edit

I tried also:

mysql://root@/test
mysql+mysqldb://root@/test

With a local dummy account with password, it works without problems.

Upvotes: 10

Views: 12102

Answers (2)

chardo
chardo

Reputation: 49

Try: mysql://root@localhost/test?

specifically: engine = create_engine('mysql://root@localhost/test?')

Upvotes: 4

SingleNegationElimination
SingleNegationElimination

Reputation: 156158

the equivalent sqlalchemy url to what you have on the command line is

mysql://root@/test

MySQL consideres the root user connecting over the standard unix socket (no -h in the command line client) to be a different user than the same username connecting via tcp

Upvotes: 2

Related Questions