The Artima Developer Community
Sponsored Link

Python Answers Forum
MySQLdb connection error

5 replies on 1 page. Most recent reply: Feb 17, 2005 12:01 AM by Jack

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Maud

Posts: 3
Nickname: maka
Registered: Feb, 2005

MySQLdb connection error Posted: Feb 14, 2005 7:58 PM
Reply to this message Reply
Advertisement
Hi,

I am trying to connect to msqldb server using a simple python script just so I can establish a connection.
Here is my simple script:

# server_version.py
import MySQLdb

conn = MySQLdb.connect( host = "localhost",
user = "testuser",
passwd = "testpass",
db = "test" )

cursor = conn.cursor()
cursor.execute("SELECT VERSION()")
row = cursor.fetchone()
print "This server version is:", row [0]
cursor.close()
conn.close()


And this is the this error message I got below:

Traceback (most recent call last):
File "server_version.py", line 8, in ?
db = "test" )
File "C:\PYTHON22\Lib\site-packages\MySQLdb\__init__.py", line 63, in Conn
return apply(Connection, args, kwargs)
File "C:\PYTHON22\Lib\site-packages\MySQLdb\connections.py", line 115, in
it__
self._make_connection(args, kwargs2)
File "C:\PYTHON22\Lib\site-packages\MySQLdb\connections.py", line 41, in _
_connection
apply(super(ConnectionBase, self).__init__, args, kwargs)
_mysql_exceptions.OperationalError: (1045, "Access denied for user: 'testuse
calhost' (Using password: YES)")

Do I need to set the connection parameters? If so, how do I go about it?

Any pointers will be greatly appreciated as I am completely new to Python and I am using it for my final year project.

Thanx,
Maka


Jack

Posts: 10
Nickname: zyppora
Registered: Jan, 2005

Re: MySQLdb connection error Posted: Feb 15, 2005 12:18 AM
Reply to this message Reply
It looks like your problem isn't in the python script. The mysql database refuses a connection. Have you set the username/password for the database so it matches what you're trying to connect to it with (i.e. 'testuser' & 'testpass')? If you have no clue on what I'm talking about, or have not set these, most probably the valid username will be 'root' without a password.

Maud

Posts: 3
Nickname: maka
Registered: Feb, 2005

Re: MySQLdb connection error Posted: Feb 15, 2005 4:47 PM
Reply to this message Reply
Thanks Jack,
I kinda have an idea(i.e. that I need to set my username and password), but don't have a clue where to go and set the username/password. Is there an existing file in mysql where I can make the changes or do I need to create one?
I poked around in the Winmysqladmin, frankly it looked like a jungle in there...

Thanks in advance.

Jack

Posts: 10
Nickname: zyppora
Registered: Jan, 2005

Re: MySQLdb connection error Posted: Feb 15, 2005 11:52 PM
Reply to this message Reply
I have no clue :P
Seriously, I run MySQL on my pc, and since I'm not all that familiar with it, I just leave it running and connect to it on localhost (I'm using it in combination with PHP to design webscripts) under root. This isn't exactly the safest way if you want to run it on a webserver or anything though.

I would refer you to http://www.mysql.com in order to find the information you seek, but I must admit that that site isn't the greatest of reference sites.

If you run both the MySQL engine and the program you're writing on your own computer (localhost), I'd say use root without a password.

Maud

Posts: 3
Nickname: maka
Registered: Feb, 2005

Re: MySQLdb connection error Posted: Feb 16, 2005 5:23 PM
Reply to this message Reply
You are right, using 'root' as user worked. I don't log in in when running MySQl, which means, I'm told, I am accessing the server via the default(root)route. I also had to leave the password parameter as an empty string.

Thank you so much for your help.

Maud

Jack

Posts: 10
Nickname: zyppora
Registered: Jan, 2005

Re: MySQLdb connection error Posted: Feb 17, 2005 12:01 AM
Reply to this message Reply
Anytime.

Flat View: This topic has 5 replies on 1 page
Topic: where to find libraries? Previous Topic   Next Topic Topic: retrieving e-mail from yahoo pop server. What's wrong?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use