Partner with experts to accelerate your digital transformation journey
Bobcares

Unlock MySQL Root Account When Access Denied for User Root Localhost Account is Locked

PDF Header PDF Footer

Learn how to unlock MySQL root account when access denied for user root localhost account is locked error appears. Simple commands and solutions inside. Our MySQL Support Team is always here to help you.

Unlock MySQL Root Account When Access Denied for User Root Localhost Account is Locked

Seeing access denied for user root localhost account is locked can throw anyone off guard, especially when applications suddenly stop connecting to the database. This error usually means that the root account in MySQL has been marked as locked. Fortunately, you can bring it back without losing your data. Let’s go through the direct commands and methods that will help you unlock the account and get things working again.

access denied for user root localhost account is locked

Why This Error Appears

This error occurs when the root account is locked due to strict security policies, repeated failed login attempts, or even after upgrades. When the account is locked, applications fail to connect and throw the following error:

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

Confirming Account Status

To be certain that the account is locked, log in with an alternative admin user and run:

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)

If the account_locked column shows Y, the account is indeed locked.

Unlocking the Account

Once confirmed, you can unlock the account with:

ALTER USER 'username'@'hostname' ACCOUNT UNLOCK;
  • ‘username’: MySQL user’s name.
  • ‘hostname’: Host or IP.
  • ACCOUNT UNLOCK: Removes the lock.

For example, if the lock is only for localhost:

ALTER USER username@localhost ACCOUNT UNLOCK;

Now, since accounts can be locked on multiple hosts, it’s better to recheck with:

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)

Run the ALTER USER … ACCOUNT UNLOCK; command again for each locked host.

Password Reset Considerations

Sometimes unlocking is not enough, especially when the default authentication plugin causes trouble. MySQL 8+ uses caching_sha2_password by default, but many prefer mysql_native_password for local setups. You may need to reset the root password after changing the plugin.

Also, pay attention to password policy variables. You can check them with:

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
6 rows in set (0.01 sec)

By lowering the policy, for instance:

SET GLOBAL validate_password.policy=LOW;

you can reset passwords with fewer restrictions. Restart MySQL after making changes, then use mysqladmin to reset the root password.

For MacBook Pro and MAMP Users

If you are on a MacBook Pro using MAMP, take a backup of your htdocs folder, uninstall MAMP, and reinstall it. This often resolves cases where the root account remains locked even after attempting changes.

[If needed, Our team is available 24/7 for additional assistance.]

Conclusion

The error access denied for user root localhost account is locked is not the end of the road. By checking the account status, unlocking it for all hosts, adjusting password policies if needed, and resetting the password, you can restore access quickly. For Mac users, a clean reinstall of MAMP may be the final step. With these methods, your database access will be back without unnecessary downtime.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Get featured on the Bobcares blog and share your expertise with a global tech audience.

WRITE FOR US
server management

Spend time on your business, not on your servers.

TALK TO US

Or click here to learn more.

Speed issues driving customers away?
We’ve got your back!

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF