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

This question already has an answer here:

I am attempting to install a network management package called cacti onto Ubuntu running under Windows Virtual PC. I attempted to install MySQL as it is one of cacti's dependencies. I can install and start the MySQL server, but whenever I try to access it in any other way, such as to change the password, I get the error message Access denied for user 'root@localhost' (using password:NO). I would like to know what is causing this and how to fix it.

Edit: (just in case my comments are not visible) The answers from HD and Devin Ceartas did not work for me.

share|improve this question

marked as duplicate by Chris S Mar 20 '13 at 5:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
What is the command you are using? –  Kyle Brandt Aug 19 '09 at 15:19
    
The command is: mysql -u root –  murgatroid99 Aug 19 '09 at 15:20
    
Same problem with -h127.0.0.1 appended to that? –  Kyle Brandt Aug 19 '09 at 15:22
    
yes, I get the same problem –  murgatroid99 Aug 19 '09 at 15:23
    
'telnet localhost 3306' opens a connection? –  Kyle Brandt Aug 19 '09 at 15:25
show 2 more comments

5 Answers 5

up vote 7 down vote accepted

You might try reseting the password with these instructions.

share|improve this answer
    
Thank you. This worked and I can now access mysql. –  murgatroid99 Aug 19 '09 at 15:32
    
You're welcome :-) –  Kyle Brandt Aug 19 '09 at 15:34
add comment

You're trying to connect to the MySQL server without a password. If you forgot it, you could try with:

sudo dpkg-reconfigure mysql-server

A dialog box will ask you for a new root user password. If you're connecting with the mysql client you need to try:

mysql -p

This command will ask you for the password, you enter before.

share|improve this answer
    
When I tried the first, nothing happened after I put in my sudo password. When I tried the second, it gave me "Access denied for user 'root@localhost' (using password:YES)." I do not remember ever setting a root password –  murgatroid99 Aug 19 '09 at 15:10
    
Which version of mysql-server have you installed? –  HD. Aug 19 '09 at 15:16
    
How do I find this out? –  murgatroid99 Aug 19 '09 at 15:18
    
dpkg -l | grep -i mysql-server –  HD. Aug 19 '09 at 15:24
    
version 5.0.51a –  murgatroid99 Aug 19 '09 at 15:25
show 1 more comment

Did you do the post-install configuration (http://dev.mysql.com/doc/refman/5.0/en/unix-post-installation.html) and permissions setup procedures (http://dev.mysql.com/doc/refman/5.0/en/default-privileges.html)?

share|improve this answer
    
The error message appeared whenever I tried to do any of those procedures. –  murgatroid99 Aug 19 '09 at 15:11
add comment

If you have never set a root password for MySQL, and you are in a fresh install normally the server does not require a password at all for connecting as root.
To setup root password for first time, use mysqladmin command at shell prompt as follows:


$ mysqladmin -u root password NEWPASSWORD
However, if you want to change (or update) a root password:

$ mysqladmin -u root -p'OLDPASSWORD' password NEWPASSWORD
If you lose the mysql server password you can use dpkg-reconfigure.

share|improve this answer
    
When I do this I get: mysqladmin: connect to server at 'localhost' failed Access denied for user 'root@localhost' (using password:NO) –  murgatroid99 Aug 19 '09 at 15:22
    
mean that the root password was set, if you have root privilege please refer to ~/.mysql_history file, it must contain the history of sql commands –  mezgani Aug 19 '09 at 18:12
add comment

This is wrong:

shell> mysqladmin --user=root create cacti  

Instead, create the MySQL database:

shell> mysqladmin --user=root --password create cacti

then type your password for the mysql root user.

share|improve this answer
add comment

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