修改用戶須要有全局的建立用戶權限、或系統 mysql 數據庫的更新權限。mysql
# 修改當前登陸的用戶的密碼 ALTER USER USER() IDENTIFIED BY 'auth_string'; # 修改指定用戶的密碼 ALTER USER 'jeffrey'@'localhost' IDENTIFIED BY 'password'; # 修改當前用戶的密碼並對現有密碼進行驗證,驗證失敗不會修改 ALTER USER 'jeffrey'@'localhost' IDENTIFIED BY 'password' REPLACE 'current_password'; # 修改指定用戶的屬性 ALTER USER 'bill'@'localhost' ATTRIBUTE '{"baz": "faz", "foo": "moo"}'; # 刪除指定用戶的某個屬性 ALTER USER 'bill'@'localhost' ATTRIBUTE '{"foo": null}'; # 修改指定用戶的 comment 屬性 ALTER USER 'bill'@'localhost' COMMENT 'Something about Bill'; # 修改指定用戶的 comment 屬性爲空字符串 ALTER USER 'bill'@'localhost' COMMENT ''; # 刪除指定用戶的 comment 屬性 ALTER USER 'bill'@'localhost' ATTRIBUTE '{"comment": null}'; # 將用戶的密碼標記爲過時,下次登陸必須修改 ALTER USER 'jeffrey'@'localhost' IDENTIFIED BY 'new_password' PASSWORD EXPIRE; # 修改用戶的角色,角色不須要存在 ALTER USER 'joe'@'10.0.0.1' DEFAULT ROLE administrator, developer; # 修改指定用戶的密碼 SET PASSWORD FOR 'jeffrey'@'localhost' = 'auth_string'; # 修改當前登陸用戶的密碼,不須要任何權限 SET PASSWORD = 'auth_string';
賬戶鎖定狀態記錄在系統表 mysql.user
的 account_locked
列中。sql
ALTER USER 'jeffrey'@'localhost' ACCOUNT LOCK; ALTER USER 'jeffrey'@'localhost' ACCOUNT UNLOCK; # 查看用戶的鎖定信息 SHOW CREATE USER user
使用鎖定的用戶登陸,會提示如下內容:數據庫
Access denied for user 'user_name'@'host_name'. Account is locked.