我正在尝试使用 Express 将 Nodejs 与 MySQL 8.0 连接起来。我的代码:
var express = require('express');
var router = express.Router();
var mysql = require('mysql');
router.get('/', function(req, res, next) {
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'rootpass'
});
connection.connect(function(err) {
if (err) throw err;
console.log('Connected!');
});
});
上面的代码在官方 Express 页面中,但我想它适用于 8.0 以下的 MySQL 版本。
当我运行项目时,我得到下一个错误:
throw err; // Rethrow non-MySQL errors
^
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Handshake.Sequence._packetToError (G:\Fractal projets\fractalpage\bfweb\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
之前安装了 MySQL