How to Lock and Unlock MySQL User Account

Lock and unlock is administrator day to day activity. ALTER USER privileges required to lock and unlock MySQL Server User. In the following example, we provided the check the status of MySQL User, lock and unlock the User account.

1. Create MySQL User.

CREATE USER harry IDENTIFIED BY 'Harry@321';

2. Check the status of the MySQL Server whether it is locked or not by running the query.

SELECT user, host, account_locked FROM mysql.user WHERE user = 'harry';

3. Lock MySQL User account:

ALTER USER 'harry' ACCOUNT LOCK;

4. Unock MySQL User account:

ALTER USER 'harry' ACCOUNT UNLOCK;

We have explained the same in the below video.