Notice that since the new password contains spaces, we’ve enclosed it in quotes.
The user and host options are for the user you want to connect as and the
server you want to connect to, respectively. You can use mysqladmin to change the password for only your own username on localhost
. For example, if
your MySQL username is sarah, you can change the password only for 'sarah'@'localhost'
. Or if you want to change the password for another username and host pair, such as 'sarah'@'sadri.invy home.com or 'susan'@'localhost'
, you’ll need to use the MySQL monitor or another more flexible MySQL client.
If you’re running
MySQL for the first time, or if your MySQL user doesn’t have a password already set, you don’t need to specify the current password—that is, you can omit the password option.
You can also remove a user’s password. Here’s an
example using the SET PASSWORDstatement:
mysql>
SET PASSWORD FOR 'selina'@'localhost' = '';Query OK, 0 rows affected (0.00 sec)
This stores the empty string as the password, allowing connections without a password parameter. Again, it’s important to always use passwords for any production server.
Sometimes, you’ll want to create anew user with
the same password as another, or you’ll want to recreate or migrate users from one installation to another. In these cases,
you may not know the plain-text
password of all users, but if you have access to the
SHOW GRANTS
statement
or the mysql database, you can discover the hashed values. If you want to create a user using a hashed password instead of asking MySQL to hash the password for you, use the
PASSWORD
keyword as follows:
mysql>
GRANT USAGE ONTO 'partmusic'@'localhost'Share with your friends: