-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Description
Bug report
Required System information
- Node.js version: 16
- Strapi version: 4.2.2
- Database: MySQL 8
- Operating system: Mac
Describe the bug
TL;DR
Mysql database driver used by Strapi does not support the new authentication method that MySQL8 uses by default.
This generates error:
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
Long story
Currently Strapi uses mysql npm package as a driver to connect to MySQL database. This package does not support the new authentication method (caching_sha2_password ) which some MySQL8 hosted databases use by default.
For example, if you deploy on Railway.app, their mysql db will refuse connection.
The solution can be either lower the security of the Database by configuring it to use the old mysql_native_password auth method or use another package for mysql driver which supports the authentication: mysql2
The details can be found in this answer in stackoverflow: https://stackoverflow.com/a/56509065/985942
Unfortunately, using the mysql2 package as a driver for the DB fails because strapi passes the client name ('mysql') as a package name to "knex" so the "knex" fails to find such a package upon loading.
Specifying a "mysql2" as a client in the config file fails too as the Strapi database package has explicit checks for "mysql" client name.
This ticket is to ask to add support for the mysql2 driver to strapi so developers can opt to install it instead of the mysql.
Since the mysql2 package is mostly API compatible with the mysqljs it should be an easy fix to treat the driver mysql2 the same way as the mysql.
Steps to reproduce the behaviour
- Create a new strapi project and configure it to use MySQL database
- Install a MySQL8 database and configure project to connect to it.
- Run Strapi project and observe it fails to connect because of the
ER_NOT_SUPPORTED_AUTH_MODEerror. - Install mysql2
npm install mysql2and change the database configuration to use "mysql2" driver. - Try to run Strapi and observe that it fails as the driver is not supported.
Expected behaviour
Should be able to select "mysql2" as a driver for a MySQL database.
UPDATE
PR for this issue: #13775
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Status