3

I'm trying to connect python with MySQL, but I get this error:

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

I'm trying to solve it for 6 hours and I fail. Can any one please help me ?

3
  • 2
    Looks like you're trying to connect to your mysql server on your localhost as root without a password. Is that the way you normally login as root? Without a password? Commented Apr 15, 2011 at 20:53
  • What OS are you using? Are you able to log in to MySQL command line as root with no password? (ie not via mysqldb? Commented Apr 15, 2011 at 20:53
  • i'm using windows 7 !! in mysql command line it ask for a pswrd and i put !!! and it work !!! Note i reinstall mysql maybe this is the problem beacuse it use to work fine !! please help me Commented Apr 15, 2011 at 21:09

5 Answers 5

1

it means that you forgot the password parameter, which in mysql is not required.

from a unix command line:

$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
$ mysql -u root -p
Enter password: 
<typing password>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.1.37-1ubuntu5.5 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

not exactly the same as logging from python,

but it's the same error, and most likely means that in your case the password argument did not make it to mysql at all.

when I type the wrong password I get a very different error on the command line:

$ mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Sign up to request clarification or add additional context in comments.

2 Comments

i'm using windows 7 can u help me please what to do !!
windows command line should be the same, maybe the parameters are \p instead of -p but if I remember right it's the -p flavor. open up a command prompt.
0

You didn't specified your root password. If you are accessing mysql from remote computer... root user is by default limited to localhost connections only. Try running this to enable access from anywhere:

GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY "YOUR_ROOT_PASSWORD";
FLUSH PRIVILEGES;

Also check your firewall settings.

1 Comment

From phpMyAdmin for example if you have it, or from console using: mysql -u root -p
0
import MySQLdb

cxn = MySQLdb.connect(host = 'localhost',user = 'root',passwd = 'password', db = 'yourdatabase')

So you need to know what your password is and you need to have created a database with:

CREATE DATABASE yourdatabase;

from the mysql command line as described above.

1 Comment

OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: YES)") the error change due to changing the password
0

I was getting this error because I had quotes in my config file.

[mysql]
username: 'uuuu'
password: 'pppp'
host: 'localhost'
database: 'dddd'

should have been

[mysql]
username: uuuu
password: pppp
host: localhost
database: dddd

Comments

0

If you don't see any value in front of the password column when you do

SELECT user, host, password FROM mysql.user;

within your mysql

In your python script don't specify the password

for example

import MySQLdb

db = MySQLdb.connect(host="localhost",    # your host, usually localhost
                     user="root",         # your username
                     passwd="",           # your password
                     db="dynamo",
                     port = 3306)         # name of the data base

# you must create a Cursor object. It will let
#  you execute all the queries you need
cur = db.cursor()

# Use all the SQL you like
cur.execute("select * from SomeTable limit 10")

# print all the first cell of all the rows
for row in cur.fetchall():
    print(row[0])

db.close()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.