Databases Reference
In-Depth Information
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 PASSWORD
statement:
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
pass
word
parameter. Again, it's important to always use passwords for any production
server.
Sometimes, you'll want to create a new user with the same password as another, or
you'll want to re-create 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 ON *.* TO 'partmusic'@'localhost'
-> IDENTIFIED BY PASSWORD '*14E65567ABDB5135D0CFD9A70B3032C179A49EE7';
Query OK, 0 rows affected (0.00 sec)
The
PASSWORD
keyword stores the hashed string directly, rather than passing it through
the
PASSWORD( )
function. You'll recall from earlier that the plain-text password was
actually
the_password
, and you'll find you can now connect using it:
$
mysql --user=partmusic --password=
the_password
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 60 to server version: 5.0.22-standard-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
You can also manually set a password to its hashed version by using the
SET PASS
WORD
statement without the
PASSWORD( )
function as follows: