estoy creando un servidor y no logro conectar a MySQL. Adjunto código de conexión que lo saqué de "https://www.npmjs.com/package/mysql#introduction", también agregué algunas opciones como debug para tratar de entender qué qué pasa:
// Imports
const mysql = require('mysql');
const { SqlPassword } = require('../../process/config');
const { logger } = require('./logger');
// Export
module.exports = {
connectDB: async () => {
const connection = mysql.createConnection({
host: 'localhost',
port: "3306",
user: 'root',
password: SqlPassword,
database: 'apple_store_la_plata_bs_as',
supportBigNumbers: true,
dateStrings: true,
debug: true
// trace: true
// insecureAuth: true
})
connection.connect((err) => {
if (err) {
logger.error('Error al conectar con MySQL:', err);
return;
}
logger.info('MySQL conectado');
return connection
});
}
};
En la consola me arroja este error:
info: Escuchando en el puerto: 8080
<-- HandshakeInitializationPacket {
protocolVersion: 10,
serverVersion: '8.3.0',
threadId: 46,
scrambleBuff1: <Buffer 72 5a 22 34 0f 58 4f 31>,
filler1: <Buffer 00>,
serverCapabilities1: 65535,
serverLanguage: 255,
serverStatus: 2,
serverCapabilities2: 57343,
scrambleLength: 21,
filler2: <Buffer 00 00 00 00 00 00 00 00 00 00>,
scrambleBuff2: <Buffer 56 05 1a 0b 7e 4c 21 18 2f 4c 54 2b>,
filler3: <Buffer 00>,
pluginData: 'caching_sha2_password',
protocol41: true
}
--> (46) ClientAuthenticationPacket {
clientFlags: 455631,
maxPacketSize: 0,
charsetNumber: 33,
filler: undefined,
user: 'root',
scrambleBuff: <Buffer ea f6 aa f8 42 dc 1c 61 97 6c 4b 38 03 d1 73 bd 6d ee 26 d3>,
database: 'apple_store_la_plata_bs_as',
protocol41: true
}
<-- (46) ErrorPacket {
fieldCount: 255,
errno: 1251,
sqlStateMarker: '#',
sqlState: '08004',
message: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client'
}
error: Error al conectar con MySQL: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client {"code":"ER_NOT_SUPPORTED_AUTH_MODE","errno":1251,"fatal":true,"sqlMessage":"Client does not support authentication protocol requested by server; consider upgrading MySQL client","sqlState":"08004","stack":"Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client\n at Sequence._packetToError (/Users/GADelucchi/Library/Mobile Documents/com~apple~CloudDocs/Apple Store La Plata Bs. As./Coding/gestion_de_ventas/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)\n at Handshake.ErrorPacket (/Users/GADelucchi/Library/Mobile Documents/com~apple~CloudDocs/Apple Store La Plata Bs. As./Coding/gestion_de_ventas/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)\n at Protocol._parsePacket (/Users/GADelucchi/Library/Mobile Documents/com~apple~CloudDocs/Apple Store La Plata Bs. As./Coding/gestion_de_ventas/node_modules/mysql/lib/protocol/Protocol.js:291:23)\n at Parser._parsePacket (/Users/GADelucchi/Library/Mobile Documents/com~apple~CloudDocs/Apple Store La Plata Bs. As./Coding/gestion_de_ventas/node_modules/mysql/lib/protocol/Parser.js:433:10)\n at Parser.write (/Users/GADelucchi/Library/Mobile Documents/com~apple~CloudDocs/Apple Store La Plata Bs. As./Coding/gestion_de_ventas/node_modules/mysql/lib/protocol/Parser.js:43:10)\n at Protocol.write (/Users/GADelucchi/Library/Mobile Documents/com~apple~CloudDocs/Apple Store La Plata Bs. As./Coding/gestion_de_ventas/node_modules/mysql/lib/protocol/Protocol.js:38:16)\n at Socket.<anonymous> (/Users/GADelucchi/Library/Mobile Documents/com~apple~CloudDocs/Apple Store La Plata Bs. As./Coding/gestion_de_ventas/node_modules/mysql/lib/Connection.js:88:28)\n at Socket.<anonymous> (/Users/GADelucchi/Library/Mobile Documents/com~apple~CloudDocs/Apple Store La Plata Bs. As./Coding/gestion_de_ventas/node_modules/mysql/lib/Connection.js:526:10)\n at Socket.emit (node:events:514:28)\n at addChunk (node:internal/streams/readable:343:12)\n --------------------\n at Protocol._enqueue (/Users/GADelucchi/Library/Mobile Documents/com~apple~CloudDocs/Apple Store La Plata Bs. As./Coding/gestion_de_ventas/node_modules/mysql/lib/protocol/Protocol.js:144:48)\n at Protocol.handshake (/Users/GADelucchi/Library/Mobile Documents/com~apple~CloudDocs/Apple Store La Plata Bs. As./Coding/gestion_de_ventas/node_modules/mysql/lib/protocol/Protocol.js:51:23)\n at Connection.connect (/Users/GADelucchi/Library/Mobile Documents/com~apple~CloudDocs/Apple Store La Plata Bs. As./Coding/gestion_de_ventas/node_modules/mysql/lib/Connection.js:116:18)\n at connectDB (/Users/GADelucchi/Library/Mobile Documents/com~apple~CloudDocs/Apple Store La Plata Bs. As./Coding/gestion_de_ventas/src/config/serverConfig.js:22:20)\n at Object.<anonymous> (/Users/GADelucchi/Library/Mobile Documents/com~apple~CloudDocs/Apple Store La Plata Bs. As./Coding/gestion_de_ventas/src/dao/factory.js:11:9)\n at Module._compile (node:internal/modules/cjs/loader:1233:14)\n at Module._extensions..js (node:internal/modules/cjs/loader:1287:10)\n at Module.load (node:internal/modules/cjs/loader:1091:32)\n at Module._load (node:internal/modules/cjs/loader:938:12)\n at Module.require (node:internal/modules/cjs/loader:1115:19)"}
Con el debug creo que entiendo que el problema está en el tipo de método, donde dice "pluginData". Por otro lado el mensaje de error dice que el cliente no soporta el protocolo de autorización. Lo que no entiendo es a quién se refiere con "cliente"; entonces no sé si debo cambiar la configuración de la conexión en Visual Studio Code o en MySQL Workbench.
Espero ansioso cualquier respuesta, gracias