Eae galera beleza? Então... Antes de eu publicar esse post, já consultei dois outros que eram parecidos com o meu, porém, um erro é incomum em relação a duvida dos colegas e por isso resolvi postar.
Então, os dados não aparecem no localhost:3000/produtos, para mostrar o erro fiz assim:
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);
}
res.send(results);
});
connection.end();
});
}
No TERMINAL aparece assim, quando é a primeira vez e utilizando o nodemon app:
[nodemon] 1.17.5
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node app`
O servidor está rodando
Mas, logo após acessar no navegador o localhost:300/produtos, não aparece nenhum item, porém, no TERMINAL aparece assim:
{ Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
at Handshake.Sequence._packetToError (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
at Handshake.ErrorPacket (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\node_modules\mysql\lib\protocol\sequences\Handshake.js:130:18)
at Protocol._parsePacket (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\node_modules\mysql\lib\protocol\Protocol.js:279:23)
at Parser.write (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\node_modules\mysql\lib\protocol\Parser.js:76:12)
at Protocol.write (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\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\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\node_modules\mysql\lib\protocol\Protocol.js:145:48)
at Protocol.handshake (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\node_modules\mysql\lib\protocol\Protocol.js:52:23)
at Connection.connect (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\node_modules\mysql\lib\Connection.js:130:18)
at Connection._implyConnect (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\node_modules\mysql\lib\Connection.js:461:10)
at Connection.query (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\node_modules\mysql\lib\Connection.js:206:8)
at C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\app\routes\produtos.js:11:14
at Layer.handle [as handle_request] (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\casadocodigo\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\rodri\Dropbox\backup\Estudo\Alura\Node.js\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 server; consider upgrading MySQL client',
sqlState: '08004',
fatal: true }
Minha versão do MYSQL É: 8.0 ; Estou utilizando o mysqlWorkbench 8.0 CE;
DB: casadocodigo_nodejs; Usuario: root e está como 127.0.0.1:3306