So I recently created a mysqljs project for node.js and i keep getting this error:

{  code: 'ER_ACCESS_DENIED_ERROR',
  errno: 1045,
  sqlMessage:
   'Access denied for user \'root\'@\'localhost\' (using password: YES)',
  sqlState: '28000',
  fatal: true }

this is my config class

const mysql = require("mysql");

exports.db = mysql.createConnection({
    host     : 'localhost',
    user     : 'root',
    password : 'password',
    database : 'test_db',
    port: 3306 //default
  });

this is my server.js

const app = require("./app");
const http = require("http");
const db = require("./config/connection").db;

const server = http.createServer(app);

server.listen("3000", function (err) {
    if (err) {
        console.log("err")
    } else {
        db.connect(function (error) {
            if (error) {
                console.log(error)
            } else {
                console.log("db connected")
            }
        })
    }
})

I can log in to my mysql cli when I mysql -u root -p and enter the password.

I have followed pretty precisely from https://github.com/mysqljs/mysql#introduction. So I assume it has something to do with my mysql? However I am not certain.

0 Answers