Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 683
Jakub M. Avatar asked Apr 05 '13 11:04

Jakub M.


2 Answers

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

like image 36
SingleNegationElimination Avatar answered Sep 24 '22 07:09

SingleNegationElimination


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

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

like image 162
chardo Avatar answered Sep 26 '22 07:09

chardo