MySQLdb not reading ~/.my.cnf ?

Dennis Schoen dennis at
Mon Jul 9 22:40:26 CEST 2001

Hi all,

I'm trying to connect to a mysql db from a python script. I can
connect without any problem when i add explicitly the username and
passwd like this:

db = MySQLdb.connect(db=sys.argv[1], user=sys.argv[2], passwd=sys.argv[3])

coming from perl I like the idea of ~/my.cnf, but when i just ommit the
parameters I get:

Traceback (most recent call last):
  File "./stuff/", line 50, in ?
    db = MySQLdb.connect()
  File "/usr/local/lib/python2.1/site-packages/MySQLdb/", line 60, in Connect
    return apply(Connection, args, kwargs)
  File "/usr/local/lib/python2.1/site-packages/MySQLdb/", line 58, in __init__
    self._db = apply(connect, args, kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user: 'dennis at localhost' (Using password: NO)")

My ~/my.cnf file works fine, when used from other applications.

Is there something I need to add or is there simply no easy way for doing this?

Python is 2.1 and MySQLdb is 0.9.0

"The Idea Is Good But The World Isn't Ready Yet"

More information about the Python-list mailing list