使用node.js连接mySQL数据库报错: Access denied for user ‘root’@‘localhost’ (using password: YES),报错代码如下:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '123456',
database : 'test'
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
if (error) throw error;
console.log('The solution is: ', results[0].solution);
});
经过百度后得知,windows 下 mySQL默认 的password不是'123456'
,而是''
,即空字符。将password修改为''
后解决问题。