The mysql connection is successful through the terminal in mac
The connection is successful through the graphical tool Navicat
Failed to connect to mysql through nodejs
Code:
function query(sql, params, callback) {
var op = {
host: '127.0.0.1',
port: '3306',
user: 'root',
password: '111111',
database: 'anjiecc'
};
var client = mysql.createConnection(op);
client.query(sql, function(err, data) {
if (err) {
console.log(err);
} else {
//調(diào)用dao回調(diào)函數(shù)
callback(data);
}
});
client.end();
}
Connection error
Access denied for user 'root'@'localhost' (using password: YES)
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlState: '28000'
Please ask God for guidance, thank you!
The account you are using does not have permission to log in to the database..
Try to authorize both localhost
and 127.0.0.1
respectively
Make sure your username and password are not entered incorrectly.
Please confirm whether you have access rights. For details, please refer to the next article: https://faceghost.com/article...
grant all privileges on . to 'root'@'localhost' identified by 'your password' with grant option;
flush privileges;