1

我正在尝试使用 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

4

1 回答 1

0

看起来您已经为用户配置了 mysql_old_auth 您可以使用此选项中的任何一个更改转换为新的身份验证协议:http ://dev.mysql.com/doc/refman/5.7/en/old-client.html或允许使用不安全的身份验证:https ://github.com/mysqljs/mysql#connection-options insecureAuth 选项

以上对我不起作用,但以下链接可以工作 https://insidemysql.com/introducing-connector-node-js-for-mysql-8-0/

于 2018-06-01T18:46:50.033 回答