search

Home  >  Q&A  >  body text

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

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!

学习ing学习ing2718 days ago975

reply all(3)I'll reply

  • 黄舟

    黄舟2017-06-12 09:22:35

    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

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-06-12 09:22:35

    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...

    reply
    0
  • 欧阳克

    欧阳克2017-06-12 09:22:35

    grant all privileges on . to 'root'@'localhost' identified by 'your password' with grant option;

    flush privileges;

    reply
    0
  • Cancelreply