Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

This is weird. Our web server is running RHEL 5.5, and has the MySQL client version 5.5.10 installed (just updated from a 5.0 build, which was having the same problem). When I connect to the database server (which is NOT localhost) via "mysql --host=dbserver -uroot -p" and provide the password, it fails with "Access denied for user 'root'@'servername' (using password: NO)". Of course, I am supplying a password. If I try to log in with a different account, and just punch in any old junk password, it fails with "Access denied for user 'otheruser'@'dbserver' (using password: YES)". So what on earth is making it refuse to supply the password when I attempt to log in as root?

For comparison, we have another internal server running Windows 2003, and it has MySQL 5.0.45 installed. I can log in with the root account from there just fine. Is there some obscure SELinux setting on our web server that's preventing the password from being sent?

(And no, I'm not trying to set up the web site to connect to the database as root. There's a dedicated user for that. This is just something that might need to be done from time to time for testing/setup.)

share|improve this question
    
Can you connect successfully without specifying the password for root? –  BMDan Apr 25 '11 at 17:42
    
Negative. Same error - root definitely has a password. I've also tried specifying the password directly on the command line. –  db2 Apr 25 '11 at 17:46
    
Start mysqld with --skip-grant-tables and run DELETE FROM mysql.user WHERE user='' OR host='';. Then restart MySQL without the --skip-grant-tables option. –  BMDan Apr 25 '11 at 17:51
    
To delete the anonymous user? Already made sure that was gone right after I set up the database server. The weird thing is that this works fine connecting from a different machine that happens to be running Windows. Seems like something is going wrong client-side, but heck if I know what. –  db2 Apr 25 '11 at 17:56
    
Well, just indulge me by running the command again, anyway? It's easy to have mistyped it, so just copy and paste from what I wrote. –  BMDan Apr 25 '11 at 18:12

2 Answers 2

up vote -1 down vote accepted

You need to explicitly grant the user permission to connect from that host- like this; (remove < > and replace with correct string)

GRANT ALL PRIVILEGES ON <dbname>.* TO '<db-username>'@'<hostname>' IDENTIFIED BY '<user-password>' WITH GRANT OPTION;
share|improve this answer
    
Well that's weird. That pretty much WAS the problem, even though there's normally a different error message for that (not allowed to connect from host, etc). I had an entry for root that was restricted to a different subnet, so I loosened it up a bit, and now I can get in. No idea why it was accusing me of not using a password, rather than why it was really failing. –  db2 Apr 25 '11 at 19:11

Stop mysql daemon.

/etc/init.d/mysqld stop

Start mysql daemon with no authorization checking.

mysqld --skip-grant-tables --user=root &

Reset the passwd. new password should be in single quotes.

mysql
mysql> UPDATE mysql.user SET Password='(hd3f6HD9Xdsr)' WHERE User='root';

mysql> FLUSH PRIVILEGES;

Restart Mysql

/etc/init.d/mysqld stop
/etc/init.d/mysqld start

Also you can add the mysql user and password as shown below in the file /root/.my.cnf, so that you can login without entering the user name and password. Just mysql is enough hereafter.

root@server [~]# cat /root/.my.cnf
[client]
user="root"
pass=":Kv95r6j"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.