MySQL 5.7.8新增了Account Lock用于锁定账号。Account Lock可以在创建账号锁定,也可以使用ALTER USER语句进行锁定。
创建账号时锁定
mysql> CREATE USER 'demo'@'localhost' IDENTIFIED BY 'a123456' ACCOUNT LOCK;
Query OK, 0 rows affected (0.00 sec)
使用ALTER USER 语句锁定
mysql>ALTER USER 'demo'@'localhost' ACCOUNT UNLOCK;
Query OK, 0 rows affected (0.00 sec)
使用被锁账号登录会报ERROR 3118错误:
$ mysql -udemo -p
Enter password:
ERROR 3118 (HY000): Access denied for user 'demo'@'localhost'. Account is locked.
解锁账号
mysql>ALTER USER 'demo'@'localhost' ACCOUNT UNLOCK;
Query OK, 0 rows affected (0.00 sec)