您的位置:首页 > 数据库 > MySQL

MySQL修改密码

2015-08-19 15:07 656 查看
A
root
account password can
be set several ways. The following discussion demonstrates three methods:

Use the
SET
PASSWORD
statement

Use the
UPDATE
statement

Use the mysqladmin command-line
client program

To assign passwords using
SET
PASSWORD
, connect to the server as
root
and
issue a
SET
PASSWORD
statement for each
root
account
listed in the
mysql.user
table.

For Unix, do this:
shell> [code]mysql -u root

mysql>
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd
');
mysql>
SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('newpwd
');
mysql>
SET PASSWORD FOR 'root'@'::1' = PASSWORD('newpwd
');
mysql>
SET PASSWORD FOR 'root'@'host_name
' = PASSWORD('
newpwd
');
[/code]

You can also use a single statement that assigns a password to all
root
accounts
by using
UPDATE
to
modify the
mysql.user
table
directly. This method works on any platform:
shell> [code]mysql -u root

mysql>
UPDATE mysql.user SET Password = PASSWORD('newpwd
')
->
WHERE User = 'root';

mysql>
FLUSH PRIVILEGES;

[/code]

The
FLUSH
statement
causes the server to reread the grant tables. Without it, the password change remains unnoticed by the server until you restart it.

To assign passwords to the
root
accounts
using mysqladmin,
execute the following commands:
shell> [code]mysqladmin -u root password "newpwd
"
shell>
mysqladmin -u root -h host_name
password "
newpwd
"
[/code]

Those commands apply both to Windows and to Unix. The double quotation marks around the password are not always necessary, but you should use them if the password contains spaces or other characters that are special to your command interpreter.
The mysqladmin method
of setting the
root
account
passwords does not work for the
'root'@'127.0.0.1'
or
'root'@'::1'
account.
Use the
SET
PASSWORD
method shown earlier.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: