Description
Description
Running npm run db:setup
when attempting to connect to a MySQL 8 database throws the following error:
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
The error above is best explained by: mysqljs/mysql#2233
TL;DR: The mysqljs/mysql
npm package does not support new authentication protocols introduced in MySQL 8. Until the PR above is merged, users will continue to receive the error above. The sample-app-nodejs
documentation does not call out that MySQL 8 is not supported, which results in confusion from consumers of this app.
Workarounds (Do Not Use in Production)
NOT RECOMMENDED FOR PRODUCTION, POTENTIAL SECURITY RISKS: https://stackoverflow.com/a/50131831/8211101
As explained by https://stackoverflow.com/a/56509065/8211101, running the command in the SO answer above negates the benefits of using MySQL 8's more secure authentication methods.
Potential Solution (Needs Investigation)
Until the mysqljs/mysql
PR is merged to support MySQL 8's new pluggable authentication methods, the mysql
package will continue to throw this error when trying to connect to a MySQL 8 database.
The mysql2
npm package (https://www.npmjs.com/package/mysql2) shares the same API as the mysql
npm package, and does support the new authentication methods. This could be researched as a potential option to replace mysql
. If mysql2
is backwards compatible with older MySQL versions, that would be ideal. Otherwise, we might need to call out that mysql
should be used for MySQL < 8 (need to verify which version mysql
breaks on), and that mysql2
should be used for MySQL 8+.