Mike Ross
Mike Ross
BABetter Auth
Created by Mike Ross on 4/12/2025 in #help
Error: Too many connections (MySQL)
I currently use better-auth in combination with a MySQL database. I use NextJS to render my website. I noticed that when making repeated changes (re-renders) better-auth throws an error:
Error: Too many connections
Error: Too many connections
. I have looked through previous posts and found that someone had the same issue when using a Prisma client. Given that I do not initialize the connection to the database myself, I was wondering how to store the connection during development? This is what my configuration looks like:
export const auth = betterAuth({
database: createPool({
host: env.DATABASE_HOST,
port: env.DATABASE_PORT,
database: env.DATABASE_NAME,
user: env.DATABASE_USER,
password: env.DATABASE_PASSWORD,
}),
emailAndPassword: {
enabled: true,
minPasswordLength: 8,
autoSignIn: true,
},
socialProviders: {
github: {
clientId: env.AUTH_GITHUB_ID,
clientSecret: env.AUTH_GITHUB_SECRET,
},
},
plugins: [nextCookies()],
})
export const auth = betterAuth({
database: createPool({
host: env.DATABASE_HOST,
port: env.DATABASE_PORT,
database: env.DATABASE_NAME,
user: env.DATABASE_USER,
password: env.DATABASE_PASSWORD,
}),
emailAndPassword: {
enabled: true,
minPasswordLength: 8,
autoSignIn: true,
},
socialProviders: {
github: {
clientId: env.AUTH_GITHUB_ID,
clientSecret: env.AUTH_GITHUB_SECRET,
},
},
plugins: [nextCookies()],
})
This is the error shown in the console:
2025-04-12T06:19:33.790Z ERROR [Better Auth]: INTERNAL_SERVER_ERROR [Error: Too many connections] {
code: 'ER_CON_COUNT_ERROR',
errno: 1040,
sqlState: '',
sqlMessage: 'Too many connections',
sql: undefined
}


⨯ [Error [APIError]: Failed to get session] {
status: 'INTERNAL_SERVER_ERROR',
body: [Object],
headers: {},
statusCode: 500,
digest: '3142529621'
}
2025-04-12T06:19:33.790Z ERROR [Better Auth]: INTERNAL_SERVER_ERROR [Error: Too many connections] {
code: 'ER_CON_COUNT_ERROR',
errno: 1040,
sqlState: '',
sqlMessage: 'Too many connections',
sql: undefined
}


⨯ [Error [APIError]: Failed to get session] {
status: 'INTERNAL_SERVER_ERROR',
body: [Object],
headers: {},
statusCode: 500,
digest: '3142529621'
}
4 replies
BABetter Auth
Created by Mike Ross on 4/5/2025 in #help
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.
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.0
error Command failed.
Exit code: 128
Command: git
Arguments: ls-remote --tags --heads ssh://[email protected]/mysql2/promise.git
Directory: /Users/user/Documents/GitHub/Project
Output:
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and 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.0
error Command failed.
Exit code: 128
Command: git
Arguments: ls-remote --tags --heads ssh://[email protected]/mysql2/promise.git
Directory: /Users/user/Documents/GitHub/Project
Output:
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and 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 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.
8 replies