天天看點

Mysql之賬戶密碼修改

根據資訊系統和資料庫安全維護要求,需要定期修改資料庫賬戶密碼。修改mysql(5.7.x版本)賬戶密碼的三種方式。

試驗環境說明:

mysql資料庫版本:5.7.32

方法一:用mysqladmin在作業系統視窗下修改

格式:mysqladmin -u使用者名 -p舊密碼 password 新密碼

例子:mysqladmin -utest -p password ‘123qwe’

[[email protected] ~]$ mysqladmin -u test -p password ‘123qwe’

Enter password:

mysqladmin: [Warning] Using a password on the command line interface can be insecure.

Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

方法二: 用SET PASSWORD指令在mysql視窗下修改

首先登入MySQL。

格式:mysql> set password for 使用者名@‘host’ = password(‘新密碼’);

例子:mysql> set password for [email protected]’%’= password(‘123456’);

mysql> set password for [email protected]’%’ = password(‘123456’);

Query OK, 0 rows affected, 1 warning (0.00 sec)

方法三:用UPDATE直接編輯mysql庫user表修改

首先登入MySQL。

mysql> use mysql;

mysql> update user set authentication_string=password(‘654321’) where user=‘test’ and host=’%’;

mysql> flush privileges;

此方法因為需要mysql庫的寫權限,需要管理者執行操作。

mysql> update user set authentication_string=password(‘654321’) where user=‘test’ and host=’%’;

Query OK, 0 rows affected, 1 warning (0.01 sec)

Rows matched: 1 Changed: 0 Warnings: 1

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)