Ao carregar a pagina está vindo em branco, depois verifiquei que está havendo um erro no modo de autenticação no cliente mysql:
código do produtos.js:
module.exports = function(app){
app.get('/produtos',function(req,res){
var mysql = require ('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'casadocodigo_nodejs'
});
connection.query('select * from livros', function(err,results){
if(err){console.log(err);}
console.log(results);
res.send(results);
});
connection.end();
});
}
Erro obtido na query:
{ Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication prot
ocol requested by server; consider upgrading MySQL client
at Handshake.Sequence._packetToError (C:\Users\Sergio\estudoNode\casadocodig
o\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
at Handshake.ErrorPacket (C:\Users\Sergio\estudoNode\casadocodigo\node_modul
es\mysql\lib\protocol\sequences\Handshake.js:130:18)
at Protocol._parsePacket (C:\Users\Sergio\estudoNode\casadocodigo\node_modul
es\mysql\lib\protocol\Protocol.js:279:23)
at Parser.write (C:\Users\Sergio\estudoNode\casadocodigo\node_modules\mysql\
lib\protocol\Parser.js:76:12)
at Protocol.write (C:\Users\Sergio\estudoNode\casadocodigo\node_modules\mysq
l\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\Users\Sergio\estudoNode\casadocodigo\node_modules\
mysql\lib\Connection.js:103:28)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
--------------------
at Protocol._enqueue (C:\Users\Sergio\estudoNode\casadocodigo\node_modules\m
ysql\lib\protocol\Protocol.js:145:48)
at Protocol.handshake (C:\Users\Sergio\estudoNode\casadocodigo\node_modules\
mysql\lib\protocol\Protocol.js:52:23)
at Connection.connect (C:\Users\Sergio\estudoNode\casadocodigo\node_modules\
mysql\lib\Connection.js:130:18)
at Connection._implyConnect (C:\Users\Sergio\estudoNode\casadocodigo\node_mo
dules\mysql\lib\Connection.js:461:10)
at Connection.query (C:\Users\Sergio\estudoNode\casadocodigo\node_modules\my
sql\lib\Connection.js:206:8)
at C:\Users\Sergio\estudoNode\casadocodigo\app\routes\produtos.js:10:16
at Layer.handle [as handle_request] (C:\Users\Sergio\estudoNode\casadocodigo
\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\Sergio\estudoNode\casadocodigo\node_modules\express\lib\ro
uter\route.js:137:13)
at Route.dispatch (C:\Users\Sergio\estudoNode\casadocodigo\node_modules\expr
ess\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\Sergio\estudoNode\casadocodigo
\node_modules\express\lib\router\layer.js:95:5)
code: 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251,
sqlMessage: 'Client does not support authentication protocol requested by serv
er; consider upgrading MySQL client',
sqlState: '08004',
fatal: true }
já tentei executar novamenteo npm install mysql --save
e já utilizei npm i npm
para atualizar o modulo do MySql, o que mais pode ser? Alguem sabe como resolver?