我正在学习node.js,但是遇到了问题。我无法以形式in
创建的node.js格式连接到数据库我根据w3schools教程学习了node.js。 我的计算机上安装了MySQL,MySQL中有用户名和密码
My code in the form to connect to the database:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "2B4jf5@=#[0]@^"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
我希望输出为“已连接!”但是
D:\nodejs\node_modules\mysql\lib\protocol\Parser.js:437
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 (D:\nodejs\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (D:\nodejs\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (D:\nodejs\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (D:\nodejs\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (D:\nodejs\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (D:\nodejs\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (D:\nodejs\node_modules\mysql\lib\Connection.js:91:28)
at Socket.<anonymous> (D:\nodejs\node_modules\mysql\lib\Connection.js:525:10)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
--------------------
at Protocol._enqueue (D:\nodejs\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (D:\nodejs\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (D:\nodejs\node_modules\mysql\lib\Connection.js:119:18)
at Object.<anonymous> (D:\nodejs\MySQL\demo_db_connection.js:22:5)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)