I am having trouble connecting node js with my database in phpmyadmin, I do not understand where this problem is coming from:
the code:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
database : 'db_client3',
user : 'root',
password : '',
});
connection.connect(function(err) {
if (err) {
console.error('Error connecting: ' + err.stack);
return;
}
console.log('Connected as id ' + connection.threadId);
});
connection.end();
However when I execute the code with the terminal, I get this error.
Command line:
node app.js
Error connecting: Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)
package.json
{
"name": "nodejs",
"version": "1.0.0",
"description": "node js test ",
"main": "app.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC"
}
Thank you for the help.
2
Answers
Try adding port like this,
Note : Make sure that you are not running anything on the given port
If it doesn’t work change your mysql version to latest in package.json.
try something like this
if issue not solve with above solution then
please check you database password and make it null and if issue is still not solve then i suggest you to Create new user instead of using root