I have been trying to get better-auth up and running with my existing NextJS project. To do so I have been following the instructions in the better auth documentation: (https://www.better-auth.com/docs/adapters/mysql). Despite that I am unable to generate the respective schemas using the
npx @better-auth/cli@latest generate
npx @better-auth/cli@latest generate
command.
In my project I use yarn as my package manager. For whatever reason trying to install the
mysql2/promise
mysql2/promise
package, as per documentation, already fails.
yarn add mysql2/promise ─╯yarn add v1.22.22[1/4] 🔍 Resolving packages...Couldn't find any versions for "mysql2" that matches "^3.14.0^"? Please choose a version of "mysql2" from this list: 3.14.0error Command failed.Exit code: 128Command: gitArguments: ls-remote --tags --heads ssh://git@github.com/mysql2/promise.gitDirectory: /Users/user/Documents/GitHub/ProjectOutput:git@github.com: Permission denied (publickey).fatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
yarn add mysql2/promise ─╯yarn add v1.22.22[1/4] 🔍 Resolving packages...Couldn't find any versions for "mysql2" that matches "^3.14.0^"? Please choose a version of "mysql2" from this list: 3.14.0error Command failed.Exit code: 128Command: gitArguments: ls-remote --tags --heads ssh://git@github.com/mysql2/promise.gitDirectory: /Users/user/Documents/GitHub/ProjectOutput:git@github.com: Permission denied (publickey).fatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
After some research I noticed that there is a package called
mysql2-promise
mysql2-promise
available via yarn, but using this package does also not allow me run the generate-schema command.
I hope someone has already figured out a way to use a MySQL database in combination with Better Auth.
Solution
Thank you for your help. I was able to fix the issue, which boils down to very basic mistake / misunderstanding. While I had tried to install the mysql2 package, I then also updated the import statement to "import {createPool } from "mysql2", which then lead to an error once again. It now works as expected.