MySQL/MySQL2 Dependency Confusion
See original GitHub issueWhat 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:
- Created 7 years ago
- Reactions:15
- Comments:13 (3 by maintainers)
Should I use mysql or mysql2?
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
notmysql2
.But for latest
master
v4
version you will need to usemysql2
😃