question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MySQL/MySQL2 Dependency Confusion

See original GitHub issue

What you are doing?

So, this is going to sound really stupid and I am a little weary to post this, but… after searching and digging, I felt I wanted to bring it up - if nothing more than as a learning experience.

I decided to play around with Sequelize this morning and just going over the docs and Getting Started example, I ran into a slight issue. The Getting Started example clearly states that after installing the core package (Sequelize) you should install a separate package so that you can work with whichever database you choose. In my case, MySQL. Well, the package it tells me to install is mysql2, so I do. But when I try to run the auth test outlined below, I receive an error. At this point, I will let the template take over…

var Sequelize = require('sequelize');

// Set-up the Sequalize Client
var db = new Sequelize(process.env.DB_DATABASE, process.env.DB_USERNAME, process.env.DB_PASSWORD, {
  host: process.env.DB_HOST,
  dialect: 'mysql',

  pool: {
    max: 5,
    min: 0,
    idle: 10000
  }

});

db.authenticate()
  .then(function(err) {
    console.log('Connection has been established successfully.');
  })
  .catch(function (err) {
    console.log('Unable to connect to the database:', err);
  });

What do you expect to happen?

'Connection has been established successfully.'

What is actually happening?

C:\sites\sequel_test\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:24
      throw new Error('Please install mysql package manually');
      ^

Error: Please install mysql package manually
    at new ConnectionManager (C:\sites\sequel_test\node_modules\sequelize\lib\dialects\mysql
\connection-manager.js:24:13)
    at new MysqlDialect (C:\sites\sequel_test\node_modules\sequelize\lib\dialects\mysql\inde
x.js:12:28)

Upon inspecting C:\sites\sequel_test\node_modules\sequelize\lib\dialects\mysql \connection-manager.js:24:13 I can clearly see that the package defaults to require('mysql') and not mysql2. Changing this line in the above file, clears up the error of course, which of course we all know is a big NO-NO!. The best way to solve this is to install the mysql package through NPM and all is good in the world again.

With that said, not sure if the Docs should be updated to reflect that the end-user should install mysql dependency and not mysql2 or the package (connection-manager.js:20:27) should be updated to mysql2.

Dialect: mysql

Sequelize version: 3.24.1

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:15
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
kahwooicommented, May 29, 2017

Should I use mysql or mysql2?

10reactions
sushantdhimancommented, Sep 5, 2016

I think you were checking master version of docs. If you look at http://docs.sequelizejs.com/en/v3/docs/getting-started/ , its still says mysql not mysql2.

But for latest master v4 version you will need to use mysql2 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

mysql2 gem compiled for wrong mysql client library
Uninstalling and reinstalling the gem will often solve this issue with no need to download and move files around by hand.
Read more >
mysql2 - npm
MySQL2 is free from native bindings and can be installed on Linux, Mac OS or Windows without any issues. npm install --save mysql2....
Read more >
Exploring extensions of dependency confusion attacks ... - Snyk
Learn about a new extension to dependency confusion which has its premise on npm's package aliasing capabilities.
Read more >
mariadb | Yarn - Package Manager
Fast, reliable, and secure dependency management. ... fast mariadb or mysql connector. ... Non-blocking MariaDB and MySQL client for Node.js.
Read more >
Node.js Rest APIs example with Express, Sequelize & MySQL
We need to install necessary modules: express , sequelize , mysql2 and cors . Run the command: npm install express sequelize mysql2 cors...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found