I can't figure it out: "manage.py dbshell" gives "Access denied for user 'ODBC'@'localhost'"

315 views
Skip to first unread message

Jumpfroggy

unread,
Sep 15, 2008, 11:02:01 AM9/15/08
to Django users
Hey All,
I've had this problem for a while and still can't figure it out. I
have django setup and working on my windows machine. I can run
manage.py syncdb and other commands, but for some reason the dbshell
command doesn't work. It just gives this error:

> manage.py dbshell
> ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)

I modified django/db/backends/mysql/client.py like another poster did
to see what credentials were being passed, and I got this:

client.py:
...
print "self.executable_name:", self.executable_name
print "args:", args
os.execvp(self.executable_name, args)
output:
> self.executable_name: mysql
> args: ['', '--user=test', '--password=test', 'test']
> ERROR 1045 (28000): Access denied for user 'ODBC'@'localhost' (using password: NO)

I also tried the following lines, with the same results:
print "os.execlp:"
os.execlp(self.executable_name, "-?")

print "os.execvp:"
os.execvp(self.executable_name, ["-?"])

These lines should simple call "mysql.exe" and print out the help
file, but instead it seems like mysql.exe is always running without
any arguments.

Does anyone have a clue why mysql.exe isn't seeing the arguments? I'd
love to figure this out and be able to use dbshell from now on.
Thanks!

Jumpfroggy

unread,
Sep 15, 2008, 11:13:34 AM9/15/08
to Django users
Alright, after some more searching I figured out my answer. First
off, the test statements I posted were wrong. The first argument
passed to execlp is the executable name, so:
> os.execlp(self.executable_name, "-?")
Should be
> os.execlp(self.executable_name, self.executable_name, "-?")

That works now. So I applied the same thing to the original client.py
file:
def runshell(self):
- args = ['']
+ args = [self.executable_name]
db = settings.DATABASE_OPTIONS.get('db',
settings.DATABASE_NAME)
user = settings.DATABASE_OPTIONS.get('user',
settings.DATABASE_USER)
...
print "self.executable_name:", self.executable_name
print "args:", args
os.execvp(self.executable_name, args)
And I get this:
> self.executable_name: mysql
> args: ['mysql', '--user=test', '--password=test', 'test']
>
> Welcome to the MySQL monitor. Commands end with ; or \g.
> Your MySQL connection id is 212
> Server version: 5.0.51a-community-nt-log MySQL Community Edition (GPL)
>
> Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
>
> mysql>

So it looks like passing '' as the first argument to execvp() on
Windows for mysql doesn't work. If using self.executable_name as the
first arg works on other platforms, it looks like this should be
changed to fix this bug and make client.py more cross-platform.

Can anyone see if it works on unix? Thanks!
Reply all
Reply to author
Forward
0 new messages