The "ER_NOT_SUPPORTED_AUTH_MODE" error indicates that the Node.js client cannot establish a connection with the MySQL server due to an unsupported authentication protocol. This issue arises when the MySQL server requires a specific authentication method that the client does not support.
In your case, you have upgraded from MariaDB to MySQL. However, the JavaScript connection snippet you are using may still be using the MariaDB authentication protocol, which is not supported by MySQL 8.0 and above.
Solution:
To resolve this issue, you need to upgrade your Node.js client to support the MySQL native authentication protocol. This protocol is compatible with both MariaDB and MySQL servers.
For MySQL version 8.0 and above, use the following command to update the root user's authentication method:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Replace "root" with the username and "password" with the desired password.
Once the authentication method has been updated, execute the following command to activate the changes:
FLUSH PRIVILEGES;
Now, modify your JavaScript connection snippet to use the MySQL native protocol:
var mysql = require('mysql'); var connection = mysql.createConnection({ host: 'localhost', user: 'root', password: 'password', database: 'foobarDb', authPlugin: 'mysql_native_password' // specify the MySQL native authentication protocol });
This should resolve the "ER_NOT_SUPPORTED_AUTH_MODE" error and allow you to connect to the MySQL database from your Node.js server.
The above is the detailed content of Why am I Getting 'ER_NOT_SUPPORTED_AUTH_MODE' Errors Connecting to MySQL from Node.js?. For more information, please follow other related articles on the PHP Chinese website!