Access denied for user ”@’localhost’ (using password: YES)【图文】

Access denied for user ”@’localhost’ (using password: YES)【图文】

操作系统:window 7 x64

mysql版本:5.6.16和5.7.27

node中的mysql模块版本:mysql@2.17.1

js代码:

// 1. 引包
var mysql = require('mysql');
// 2. 创建连接
var connection = mysql.CreateConnection({
    host: 'localhost',
    user: 'root',
    password: '8888',
    datavase: 'mysql'
});

// 3. 连接数据库
connection.connect();

// 4. 增,删,改,查
connection.query('show tables', function (error, results, firlds) {
    if (error) throw error;
    console.log('students is :', results);
});

// 5. 关闭连接
connection.end();

解决方法:

到mysql目录下创建一个my.ini的文件,在文件加入以下内容

[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
skip-grant-tables

Access denied for user ”@’localhost’ (using password: YES)【图文】

然后重启mysql服务

评论
:broken_heart: :confounded: :flushed: :frowning: :grinning: :heart: :kissing_heart: :mask: :pensive: :rage: :relaxed: :scream: :smile: :smirk: :sob: :stuck_out_tongue_closed_eyes: :stuck_out_tongue_winking_eye: :wink: