To fix Node and MySQL – ER_ACCESS_DENIED_ERROR Access denied for user ‘root’@’localhost’ error, we should make sure we connect with the right credentials.
For instance, we write
const mysql = require("mysql");
const connection = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
});
to call createConnection
with an object with the user
userame and password
password to the host
host.