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

  errno: 1045,
   '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) {
    } else {
        db.connect(function (error) {
            if (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 So I assume it has something to do with my mysql? However I am not certain.

0 Answers