繁体   English   中英

错误连接到数据库:错误:ER_NOT_SUPPORTED_AUTH_MODE:客户端不支持服务器请求的身份验证协议

[英]Error Connecting to the database: Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server

我尝试按照此链接中的建议进行操作: MySQL 8.0 - 客户端不支持服务器请求的身份验证协议; 考虑升级 MySQL 客户端

并且我知道它使用的是 cahcing_sha2_password 而不是 mysql_native。 但是,我尝试按照建议进行操作,但仍然收到相同的错误,尝试使用 node.js 连接到数据库。

架构名称:'my_db'

//DATABASE CONNECTION SETTINGS
const APIServerPort = 3001;

const database = {
  host: "localhost",
  port: 3306,
  user: "root",
  password: "xxx",
  database: "my_db"
};

module.exports = {
  database,
  APIServerPort
};

app.js 文件:

const express = require("express");
const app = express();
const router = express.Router();
const settings = require("./settings");
const routes = require("./routes");
const mysql = require("mysql");

const connection = mysql.createConnection(settings.database);

router.get("/employees", routes.employees.listAllEmployees);

app.use("/apis", router);

connection.connect(error => {
  if (error) {
    console.error("Error Connecting to the database: " + error);
    return process.exit();
  }

  app.listen(settings.APIServerPort, () =>
    console.info(`Server is running at port ${settings.APIServerPort}...`)
  );
});

SQL 查询运行:

CREATE USER 'root'@'localhost:3301/apis/employees' IDENTIFIED WITH mysql_native_password BY 'xxx';
FLUSH PRIVILEGES;

但是,我仍然收到相同的错误。

mysql 用户的格式为'root'@'localhost' Urls 只是一个 node.js 概念。

由于该用户已经存在,请创建一个新用户:

CREATE USER myapplication@localhost
  IDENTIFIED WITH mysql_native_password BY 'xxx';
GRANT ALL ON my_db.* TO myapplication@localhost`;

你不需要FLUSH PRIVILEGES

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM