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 {
//调用dao回调函数
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
and127.0.0.1
respectivelyMake 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;