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.

i am on ec2 plain linux and wish to change my mySQL password
ive tried:

sudo mysqladmin -u root -p '***old***' password '***new****'

then it prompts me to enter password
then i enter ***old***

but i keep getting an error message

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)'


question: how do i change my current password?

edit:
when i put this in, no space in between -p and the old password i get a list of definition

sudo mysqladmin -u root -p'***old***'


when i put this in

sudo mysqladmin -u root -p password '***new***'

i get the same error message as above

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted
  1. If you use the short option form (-p), you cannot have a space between the option and the password. Additionally, If you specify the password as part of the command, you should not be prompted for it (however, because of the space, your password is actually recognized as a separate command). (1)

    • It would be better to let the system prompt you for your password - this avoids confusion with spaces, quoting, and special characters, and the password doesn't show up in your history. (Note that the old password is omitted):

      sudo mysqladmin -u root -p password 'NEW_PASSWORD'
  2. Passwords containing special characters must be enclosed in single quotes (which you have already done). (2)

  3. Alternatively, you can perform the entire task using the mysql client and queries (3):

    mysql -u root -p
    Enter password:
    mysql> UPDATE mysql.user SET Password=PASSWORD('NEW_PASSWORD') WHERE User='root';
    mysql> FLUSH PRIVILEGES;

    (Note the above will change the password for all 'Hosts'. You can add AND Host='localhost' to restrict it to just localhost.)

    • Alternatively, at the mysql prompt, you can use:

      mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('NEW_PASSWORD');

If you can't login to mysql directly (mysql -u root -p), then you have a different problem - possibly relating to special characters in your password (I find this is true when entering a password with special characters in mysql_secure_installation). The MySQL manual describes how to reset a root password, if needed, here.

share|improve this answer
    
dont have any special characters, tried running sql queries in mysql workbench but got errors –  t q Apr 4 '12 at 23:55
    
a) Can you login to the mysql client (mysql -u root -p) or do you get 'Access Denied'? b) What were the errors? c) Also are you specifically running RedHat (you use it in your title, but wrote 'ec2 plain linux' in your question). d) Just to confirm, your MySQL server is running on the same EC2 instance that you are running the commands from, right? –  cyberx86 Apr 5 '12 at 0:03
    
it is a redhat distro, linux on ec2. question a. i am getting the same error as above. question d. yes. note: i am not logged in as root, i have been using sudo –  t q Apr 5 '12 at 0:07
    
The error given almost always means that you have the wrong password. You could try mysql --no-defaults -u root -p to ensure that no option files are overriding your password, but otherwise (and especially since you are trying to change your password anyway) I may suggest simply resetting your mysql root password and proceeding from there. –  cyberx86 Apr 5 '12 at 0:17
    
logged in mysql -u myuser -p, i the username for mysql was different. THANK YOU!!!! –  t q Apr 5 '12 at 0:18
add comment

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.