mysql> exit Bye [root@mysql1 ~]# mysql -uroot -p Enter password: --此時(shí)輸入老密碼會(huì)出現(xiàn)如下提示 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) [root@mysql1 ~]# mysql -uroot -p Enter password: --此時(shí)輸入新密碼連接成功 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種方法來(lái)指定密碼,你還可以直接修改user表:
要想在創(chuàng)建新賬戶時(shí)建立密碼,在Password列提供一個(gè)值:
shell> mysql -u root mysql mysql> INSERT INTO user (Host,User,Password) -> VALUES('%','jeffrey',PASSWORD('biscuit')); mysql> FLUSH PRIVILEGES;
要想更改已有賬戶的密碼,使用UPDATE來(lái)設(shè)置Password列值:
shell> mysql -u root mysql mysql> UPDATE user SET Password = PASSWORD('bagel') -> WHERE Host = '%' AND User = 'francis'; mysql> FLUSH PRIVILEGES; 當(dāng)你使用SET PASSWORD、INSERT或UPDATE指定賬戶的密碼時(shí),必須用PASSWORD()函數(shù)對(duì)它進(jìn)行加密。(唯一的特例是如果密碼為空,你不需要使用PASSWORD())。 需要使用PASSWORD()是因?yàn)閡ser表以加密方式保存密碼,而不是明文。如果你忘記了,你可能會(huì)象這樣設(shè)置密碼:
shell> mysql -u root mysql mysql> INSERT INTO user (Host,User,Password) -> VALUES('%','jeffrey','biscuit'); mysql> FLUSH PRIVILEGES;