javascript - Access denied for user 'root'@'localhost' (using password: YES)

查看:133
本文介绍了javascript - Access denied for user 'root'@'localhost' (using password: YES)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

在mac中通过终端连接mysql连接成功
通过图形工具Navicat 连接成功

通过nodejs连接mysql失败

代码:

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();
}

连接报错
Access denied for user 'root'@'localhost' (using password: YES)
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlState: '28000'

求大神指导指导,谢谢!

解决方案

grant all privileges on . to 'root'@'localhost' identified by '你的密码' with grant option;

flush privileges;

这篇关于javascript - Access denied for user 'root'@'localhost' (using password: YES)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆