mysql> exit Bye [root@mysql1 ~]# mysql -uroot -p Enter password: --此时输入老密码会出现如下提示 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) [root@mysql1 ~]# mysql -uroot -p Enter password: --此时输入新密码连接成功 Welcome to the MySQL monitor. Commands end with ; or /g. Your MySQL connection id is 11 Server version: 5.6.30 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
mysql> GRANT USAGE ON *.* TO 'jeffrey'@'%' IDENTIFIED BY 'biscuit';
一般情况下最好使用上述3种方法来指定密码,你还可以直接修改user表:
要想在创建新账户时建立密码,在Password列提供一个值:
shell> mysql -u root mysql mysql> INSERT INTO user (Host,User,Password) -> VALUES('%','jeffrey',PASSWORD('biscuit')); mysql> FLUSH PRIVILEGES;
要想更改已有账户的密码,使用UPDATE来设置Password列值:
shell> mysql -u root mysql mysql> UPDATE user SET Password = PASSWORD('bagel') -> WHERE Host = '%' AND User = 'francis'; mysql> FLUSH PRIVILEGES; 当你使用SET PASSWORD、INSERT或UPDATE指定账户的密码时,必须用PASSWORD()函数对它进行加密。(唯一的特例是如果密码为空,你不需要使用PASSWORD())。 需要使用PASSWORD()是因为user表以加密方式保存密码,而不是明文。如果你忘记了,你可能会象这样设置密码:
shell> mysql -u root mysql mysql> INSERT INTO user (Host,User,Password) -> VALUES('%','jeffrey','biscuit'); mysql> FLUSH PRIVILEGES;