Reputation: 1
I am writing a sign up/login page with node, using express, MySQL, dotenv, hbs e bcryptjs and nodemon. I run the code (which is below), but console returns me this error:
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlMessage: "Access denied for user ''@'localhost' (using password: NO)",
sqlState: '28000',
fatal: true
I am already running it on a admin user, and tried to give it permission by using SQL commands, but it didn't work.
It appears to be a error in my code or structure, not in SQL, since I got this error in two different computers, one having admin privileges and the other notFolder Structure
app.js
const express = require('express');
const mysql = require("mysql");
const dotenv = require('dotenv');
const app = express();
dotenv.config({ path: './.env'});
const db = mysql.createConnection({
host: process.env.DATABASE_HOST,
user: process.env.DATABASE_USER,
password: process.env.DATABASE_PASSWORD,
database: process.env.DATABASE
});
db.connect((error) => {
if(error) {
console.log(error)
} else {
console.log("MySQL connected!")
}
})
process.env
DATABASE = logindb
DATABASE_HOST = localhost
DATABASE_ROOT = root
DATABASE_PASSWORD =
What I tried with SQL:
create database logindb;
CREATE TABLE users (
id INT(11) NOT NULL AUTO_INCREMENT,
NAME VARCHAR(100),
email VARCHAR(100),
PASSWORD VARCHAR(255),
PRIMARY KEY (id)
)
GRANT ALL PRIVILEGES ON users.* TO 'anajo'@'localhost' IDENTIFIED BY '';
FLUSH privileges
SHOW GRANTS FOR 'anajo'@'localhost';
Upvotes: 0
Views: 29