Sequelize cannot find the mysql2 driver
Error: Please install mysql2 package manuallyShort answer
Sequelize does not ship database drivers. For the mysql dialect it needs the mysql2 package installed in the same project, and each other dialect needs its own driver. Install mysql2 with npm, or change the dialect to match the driver you already have.
Fix it fast
1Find out which cause you have
Ask npm whether the driver is installed in the project that runs Sequelize, and check which dialect you configured.
npm ls mysql2 grep -rn "dialect" src/ config/2Match what you see, then jump to its fix
What does the error look like?
Error: Please install mysql2 package manually
Cause 1 of 2
The driver package is not installed
1Check
The Sequelize getting-started guide lists the driver as a separate install: you add sequelize, then one driver for your database. Missing from package.json means Sequelize cannot load it.
npm ls mysql2
grep -n "mysql2" package.json2Fix
Install it into the project that runs the app and save it as a dependency.
npm install --save mysql23Verify
npm ls shows the version and the app starts.
npm ls mysql2
node -e "require('mysql2'); console.log('driver loads')"Confirmed by sequelize.org
Cause 2 of 2
The dialect and the installed driver do not match
1Check
Each dialect has its own package: mysql2 for MySQL, mariadb for MariaDB, pg with pg-hstore for Postgres, sqlite3 for SQLite, tedious for SQL Server. The dialect string must agree with what you installed.
grep -rn "dialect" src/ config/
npm ls --depth=02Fix
Either install the driver for the dialect you set, or set the dialect to the one you installed. The accepted values include mysql, postgres, sqlite, mariadb and mssql.
const sequelize = new Sequelize('db', 'user', 'pass', {
host: 'localhost',
dialect: 'mysql', // needs: npm install --save mysql2
});3Verify
sequelize.authenticate() succeeds.
await sequelize.authenticate();
console.log('connected');Confirmed by sequelize.org
How do I stop it coming back?
- Add the driver to package.json in the same commit that sets the dialect.
- In a monorepo, install the driver in the package that creates the Sequelize instance.
- If your build setup cannot find drivers on its own, pass the loaded module explicitly with the dialectModule option.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fixBack end
The command npm run build -- --prod exited with code 1 (Angular)
The command "npm run build -- --prod" exited with code 1
Exit code 1 only says the build failed; the real message is above it.
2 causes, each with a fix