[英]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.