O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Locking users

If you find any issues with the account, you can lock it. MySQL supports locking while using CREATE USER or ALTER USER.

Lock the account by adding the ACCOUNT LOCK clause to the ALTER USER statement:

mysql> ALTER USER 'developer'@'%' ACCOUNT LOCK;Query OK, 0 rows affected (0.05 sec)

The developer will get an error saying that the account is locked:

shell> mysql -u developer -pnew_company_passmysql: [Warning] Using a password on the command line interface can be insecure.ERROR 3118 (HY000): Access denied for user 'developer'@'localhost'. Account is locked.

You can unlock the account after confirming:

mysql> ALTER USER 'developer'@'%' ACCOUNT UNLOCK;Query OK, 0 rows affected (0.00 sec)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required