Bobcares

[RESOLVED] MySQL the server requested authentication method unknown to the client

by | Mar 21, 2020

Oops! MySQL just showed the error ‘The server requested authentication method unknown to the client‘. Usually, the error shows up when a user tries to connect to the database. The reason for this error is improper authentication plugin settings in MySQL. At Bobcares, we often get requests to fix MySQL errors, as a part of our Server Management Services. Today, let’s see how our Support Engineers fix this error.

Overview
  1. MySQL the server requested authentication method unknown to the client: Common Causes
  2. How does the MySQL server authenticate a client?
  3. Why does MySQL show the authentication method unknown to the client?
  4. How we fix the error authentication method unknown to the client?
  5. Other Fixes for the Issue
  6. Conclusion

MySQL the server requested authentication method unknown to the client: Common Causes

Some of the main Causes behind the issue are the following:

1. MySQL 8 Default Authentication: The server uses caching_sha2_password, whereas the client wants mysql_native_password.

2. Invalid Password: The password we entered is invalid or has expired.

3. Network Problems: Poor network connectivity can inhibit successful authentication.

4. Client Settings: The client application may have improper MySQL connection settings.

How does the MySQL server authenticate a client?

A PHP application connects to the MySQL server using the username provided by the server/hosting provider. The server validates the user and returns the connection status. MySQL uses caching_sha2_password and auth_socket plugins for validation.

The caching_sha2_password plugin uses an SHA-2 algorithm with 256-bit password encryption. MySQL 8 prefers this auth method. Whereas the auth_socket plugin checks if the socket username matches with the MySQL username. If the names don’t match, it checks for the socket username of the mysql.user. If a match is found, the plugin permits the connection. But to serve the pre 8.0 clients and avoid compatibility errors, it is preferred to revert back the auth method. Older versions of MySQL use mysql_native_password plugin for validation.

 

Why does MySQL show the authentication method unknown to the client?

Recently one of our customers approached us with a MySQL auth error. The error showed up in MySQL 8. But the user had a PHP version 7.0. The default authentication plugin used by the MySQL is auth_socket.

Here MySQL client like PHPMyAdmin authenticates the user to login to the database by a password. Hence when a user tries to access the database using PHPMyAdmin ends up in the auth error. But the actual reason was compatibility error.

The error message is ‘The server requested authentication method unknown to the client‘. In PHPMyAdmin, the error appears as,

MySQL the server requested authentication method unknown to the client

Now let’s see how our Support Engineers fix this error.

How we fix the error authentication method unknown to the client?

To fix this error we changed the default authentication plugin used by MySQL. For this, we logged in to MySQL as the root user. Then we run the command,

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Here we replaced the ‘password‘ with the password of the root user. If the database user is not root user, replace the username and password respectively. Finally, this fixed the error. And the user was able to log in to PHPMyAdmin successfully.

But this is a temporary fix as the MySQL 8 uses PHP 7.0. The preferred auth plugin for this version is caching_sha2_password. Hence we also recommend the users to upgrade the pre 8.0 clients to avoid further errors.

Other Fixes for the Issue

1. Upgrade MySQL Client: We must update the MySQL client, application, or driver to a version compatible with the MySQL server’s authentication method. For PHP applications, ensure PHP MySQL extensions (mysqli or PDO_MySQL) are up to date.

2. Check MySQL Server Configuration: We can edit the MySQL configuration file (my.cnf or my.ini). Then, add or modify under the [mysqld] section:

[mysqld] default_authentication_plugin=mysql_native_password

Restart MySQL to apply changes.

3. Recreate User with Specific Authentication Plugin: Initially, log into MySQL and delete the existing user. Then, recreate the user with the mysql_native_password plugin:

DROP USER 'username'@'hostname';
CREATE USER 'username'@'hostname' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'hostname';
FLUSH PRIVILEGES;

Replace placeholders (username, hostname, etc.) with actual values.

4. Ensure Application Compatibility:

We must also make sure the application’s database connection settings support the MySQL server’s authentication method. Update the connection library or configuration if needed.

[Still, having trouble in fixing MySQL errors? – We can help you.]

Conclusion

In short, MySQL error the server requested authentication method unknown to the client occurs due to the default authentication plugin used. Today, we saw how our Support Engineers changes this to fix the error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

10 Comments

  1. Dan

    Perfect solution! Thanks.

    Reply
  2. Nicolás

    It worked great, Thanks!

    Reply
  3. flassi

    Thank you, this solved my problem also, mine was MYSQLI extension problem

    Reply
    • Hiba Razak

      Glad to know that our article helps you solves the issue 🙂 .

      Reply
  4. Henry

    Me salvó la vida, muchas gracias, mil likes para esta página ♥

    Reply
    • Hiba Razak

      Hi Henry,
      Glad to know that our article helps you solves the issue ? .

      Reply
  5. marcio dias

    Não funcionou pra mim. Estou usando o Php 5.6

    Reply
    • Hiba Razak

      Hi,
      Please contact our support team via live chat(click on the icon at right-bottom).

      Reply
  6. CARLOS GAYTAN NARES

    EXCELENTE SOLUCION.

    Reply
    • Hiba Razak

      Hi,
      Thanks for the feedback. We are glad to know that our article was helpful for you 🙂 .

      Reply

Submit a Comment

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

Never again lose customers to poor
server speed! Let us help you.

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