You are currently viewing How to fix MySQL ‘username’@’localhost’. Account is locked.

How to fix MySQL ‘username’@’localhost’. Account is locked.

Symptoms

Applications are unable to access the MySQL database and report the following error:

[3118] Access denied for user 'username'@'localhost'. Account is locked.

Description 

This error occurs when the account being used to access a database is marked as locked in MySQL:

mysql> SELECT user, host, account_locked FROM mysql.user where user = 'username';
+------------------+--------------------------+----------------+
| user             | host                     | account_locked |
+------------------+--------------------------+----------------+
| username         | localhost                | Y              |
+------------------+--------------------------+----------------+
4 rows in set (0.00 sec)

Workaround

You can check the status of an account with the following command. Be sure to replace username with the MySQL user you would like to check:

mysql> SELECT user, host, account_locked FROM mysql.user where user = 'username';

You can unlock the account for a particular host using the ‘ACCOUNT UNLOCK’ clause. Be sure to replace username with the MySQL user you would like to unlock:

ALTER USER username@localhost ACCOUNT UNLOCK;

You may need to run these commands multiple times if the account is locked for multiple hosts:

mysql> SELECT user, host, account_locked FROM mysql.user WHERE user = 'username';
+-------+---------------------------+----------------+
| user | host | account_locked |
+-------+---------------------------+----------------+
| username | 10.0.0.2 | Y |
| username | localhost | N |
| username | cloudlinux7.11-90-0-6.tld | Y |
+-------+---------------------------+----------------+
4 rows in set (0.00 sec)

You can read more about account locking in MySQL’s documentation below:

https://dev.mysql.com/doc/mysql-security-excerpt/5.7/en/account-locking.html

Jobair Alam Bipul

I'm Jobair Alam, a cPanel Certified WHM/cPanel server administrator and web hosting expert with over 10 years of experience in the industry.

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

HostArmada - Affordable Cloud SSD Web Hosting