Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Sequelize cannot find the mysql2 driver

ErrorError: Please install mysql2 package manually

Short 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.

  • Applies to Sequelize 6, Node.js 22, mysql2
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/
  2. 2Match what you see, then jump to its fix

    1. 1npm ls mysql2 prints (empty)The driver package is not installedFix
    2. 2The dialect value is mysql, but you installed mariadb or another driver (or the reverse)The dialect and the installed driver do not matchFix

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.json

2Fix

Install it into the project that runs the app and save it as a dependency.

npm install --save mysql2

3Verify

npm ls shows the version and the app starts.

npm ls mysql2
node -e "require('mysql2'); console.log('driver loads')"

Confirmed by sequelize.org

Did this fix it?

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=0

2Fix

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

Did this fix it?

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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.