Reputation: 3562
I'm trying to connect Sequelize to a local mySql instance. In testing I started out with Sqlite which works fine. Now I'm switching over to MySql getting a access denied error within my unit tests. This is a node.js project loading the sequelize module environment variables are being set using .env for local testing. Within the project I have a models directory which initializes the sequelize context:
models/index.js
let sequelize = {};
if (typeof process.env !== 'undefined' && process.env.ENVIRONMENT === 'production') {
sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.PASSWORD,
{ host: process.env.DB_HOST, dialect: process.env.MYSQLDIALECT, port: process.env.DB_PORT });
} else if(process.env !== 'undefined' && process.env.ENVIRONMENT === 'development') {
sequelize = new Sequelize({dialect: process.env.DIALECT, storage: process.env.STORAGE});
}
.env
ENVIRONMENT=production
DB_NAME='MYRDSDataStore'
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER='sqlserviceuser'
DB_PASSWORD='password'
MYSQLDIALECT='mysql'
SQLITEDIALECT='sqlite'
STORAGE='db.sqlite'
Host is set to 127.0.0.1 but I have also tried localhost and received the same error.
index.test.spec.js
describe('Create Audit Table and insert error object', ()=>{
it('Creates audit table and inserts record',()=>{
let errorObject ={
errorCode: '300',
event: 'POST',
userName: 'testUser',
message: 'Error message from test'
}
util.AuditLogger(errorObject)
.then(()=>{
model.Audit.findAll({
attributes: ['errorCode']
}).then((data)=>{
expect(data).to.have.lengthOf.at.least(1);
});
});
});
});
When I run my unit test I get the following exception:
Unhandled rejection SequelizeAccessDeniedError: Access denied for user 'sqlserviceuser'@'localhost' (using password: NO)
The user sqlserviceuser is a new user I created using sql workbench and granted the user dbo role (so they currently have full access)
From a terminal window I've tried the following command:
mysql -h localhost -u sqlserviceuser -p MYRDSDataStore
typing this I am then prompted for password which then allows me to login followed with the login message:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 29
Server version: 8.0.15 MySQL Community Server - GPL
Can anyone provide any suggestions or ideas as to why Sequelize would be failing or what I need to change to allow Sequelize to connect?
Thanks
Upvotes: 1
Views: 12315
Reputation: 329
sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.PASSWORD
->
sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASSWORD
should be the problem here
Upvotes: 0