Better Auth + MySQL - Failing Schema Generation
Hey guys,
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
command.
In my project I use yarn as my package manager. For whatever reason trying to install the mysql2/promise
package, as per documentation, already fails.
After some research I noticed that there is a package called 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:Jump to 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.
5 Replies
https://sidorares.github.io/node-mysql2/docs/documentation/typescript-examples can u pls do the installation guide and see if this works for you
Using MySQL2 with TypeScript | Quickstart
Installation
When using the
mysql2-promise
package (https://classic.yarnpkg.com/en/package/mysql2-promise) in combination with this better-auth configuration:
I get the following error when running npx @better-auth/cli@latest generate
:
Note that the mysql database is up and running and accessible.Will do
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.
glad you fixed it