MySQL使用ALTER USER修改密碼
本文將介紹在 MySQL 中怎樣使用 alter user 修改用戶密碼。
mysql>
alter
user
test identified
by
'123456'
;
Query OK, 0
rows
affected
|
(2)修改當前登錄用戶的密碼,其中:user() 方法將返回當前用戶信息。實例如下:
mysql>
select
user
();
+
----------------+
|
user
() |
+
----------------+
| test@localhost |
+
----------------+
1 row
in
set
(0.00 sec)
mysql>
alter
user
user
() identified
by
'aaaaaa'
;
Query OK, 0
rows
affected (0.00 sec)
|
(3)使密碼過期
mysql>
alter
user
test identified
by
'123456'
password
expire;
Query OK, 0
rows
affecte
|
(4)使密碼從不過期
mysql>
alter
user
test identified
by
'123456'
password
expire never;
Query OK, 0
rows
affected
|
(5)按默認設置過期時間
mysql>
alter
user
test identified
by
'123456'
password
expire
default
;
Query OK, 0
rows
affected
|
(6)指定密碼的過期間隔,如下:
mysql>
alter
user
test identified
by
'123456'
password
expire interval 90
day
;
Query OK, 0
rows
affected
|
在 MySQL 文檔里,推薦使用 ALTER USER 修改用戶密碼。ALTER USER 官網參考手冊:https://dev.mysql.com/doc/refman/5.7/en/alter-user.html
SET PASSWORD
使用 SET PASSWORD 的密碼有兩種:
(1)使用默認加密
mysql>
set
password
for
test=
'123456'
;
ERROR 1372 (HY000):
Password
hash should be a 41-digit hexadecimal number
|
錯誤“ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number”(密碼散列應該是一個41位的十六進制數字)意思是不能輸入明文,可以使用 password('') 來生成密碼。
(2)使用 PASSWORD() 函數加密
mysql>
set
password
for
test=
password
(
'123abc'
);
Query OK, 0
rows
affected
|
注意:使用 PASSWORD('auth_string') 的方式已經被廢棄,在以后的版本會把它移除,所以不建議使用它來修改密碼。
我們愈是學習,愈覺得自己的貧乏。 —— 雪萊
COME FROM :https://www.hxstrive.com/article/728.htm#page1