Node.js Authentication Issues with MySQL 8.0
When trying to connect to a MySQL database with the root account using Node.js, certain issues may arise. This is particularly relevant with MySQL 8.0, where the default authentication plugin has changed from mysql_native_password to caching_sha2_password.
Error Message and Cause
When attempting to connect to MySQL 8.0 with a Node.js application, the following error might occur:
ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
This error indicates that the Node.js MySQL driver is unable to use the new authentication plugin introduced in MySQL 8.0.
Workaround:
To resolve the issue and connect to MySQL 8.0 using the root account, the mysql_native_password plugin can be used instead of the default caching_sha2_password. This can be achieved through one of the following methods:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'MyNewPass';
CREATE USER 'foo'@'localhost' IDENTIFIED WITH mysql_native_password BY 'bar';
Alternative Solution:
Alternatively, the official MySQL Node.js connector, which is based on the X Protocol, can be utilized. This connector supports the new authentication mode in MySQL 8.0.
The above is the detailed content of Why is My Node.js App Failing to Authenticate with MySQL 8.0?. For more information, please follow other related articles on the PHP Chinese website!