Heim  >  Fragen und Antworten  >  Hauptteil

javascript – Zugriff für Benutzer „root“@„localhost“ verweigert (mit Passwort: JA)

Verbinden Sie sich über das Terminal im Mac mit MySQL und die Verbindung ist erfolgreich
Die Verbindung ist über das grafische Tool Navicat erfolgreich

Es konnte keine Verbindung zu MySQL über NodeJS hergestellt werden

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

Verbindungsfehler
Zugriff verweigert für Benutzer 'root'@'localhost' (mit Passwort: JA)
Code: 'ER_ACCESS_DENIED_ERROR',
Fehlernummer: 1045,
SQL-Status: '28000'

Bitte bitte Gott um Führung, danke!

学习ing学习ing2686 Tage vor932

Antworte allen(3)Ich werde antworten

  • 黄舟

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

    所用账号没权限登录数据库吧..
    试下在localhost127.0.0.1都分别授权吧

    Antwort
    0
  • 仅有的幸福

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

    确定您的用户名和密码没有输入错误的话。
    请确定是否有访问权限,具体可参看下篇文章:https://faceghost.com/article...

    Antwort
    0
  • 欧阳克

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

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

    flush privileges;

    Antwort
    0
  • StornierenAntwort