0

I am getting this error, but none of the solutions worked for me

Error: ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: YES)

I tried the solutions posted online but they did not work. I can connect to my server in Python, but not in NodeJS despite having the MySQL module installed.

var con = mysql.createConnection({host: "localhost", port: 3306, username: "root", password: "password", database: "activity"})

For some reason, the error message does not show user 'root'@'localhost', but rather an empty user. I do not know why this isn't working, since I am able to connect to my database in python. I've tried flushing privileges and other solutions posted online, but none work. MySQL server does run on port 3306

1
  • change username to user in config Commented Aug 15, 2020 at 20:08

1 Answer 1

1
var mysql = require('mysql');

var con = mysql.createConnection({
  host: "localhost",
  user: "root",
  password: "password",
  database: "activity"
});

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
  var sql = "CREATE TABLE customers (name VARCHAR(255), address VARCHAR(255))";
  con.query(sql, function (err, result) {
    if (err) throw err;
    console.log("Table created");
  });
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.