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
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):
Passwords containing special characters must be enclosed in single quotes (which you have already done). (2)
Alternatively, you can perform the entire task using the mysql client and queries (3):
(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:
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 inmysql_secure_installation
). The MySQL manual describes how to reset a root password, if needed, here.