I have a project that I developed several years ago, it accesses my local instance of MariaDB:
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 41
Server version: 11.2.2-MariaDB Homebrew
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Reading history-file /Users/sy/.mysql_history
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
I’m working on iMAC:
macOS Monterey
Version 12.7.5
iMac (Retina 5K, 27-inch, Late 2015)
Processor 4 GHz Quad-Core Intel Core i7
Memory 16 GB 1867 MHz DDR3
Startup Disk Macintosh HD
Graphics AMD Radeon R9 M395X 4 GB
The version of node.js:
v21.4.0
With MySQLWorkbench I can connect to the database, I have the use the same credentials in my node application and the result is:
mySQL connection error: Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)
node:events:510
throw err; // Unhandled 'error' event
^
Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('20/05/2024 10:53:15x1B[31m ERRORx1B[0m caught in mimic.js:socket.on(loadmimic):line 834:n' +
"mySQL connection error: Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)")
at Socket.emit (node:events:508:17)
at Socket.emit (/Users/sy/nodeTest/node_modules/socket.io/lib/socket.js:129:10)
at Object.msg (/Users/sy/nodeTest/svr/err.js:58:24)
at Handshake._callback (/Users/sy/nodeTest/mimic.js:831:27)
at Sequence.end (/Users/sy/nodeTest/node_modules/mysql/lib/protocol/sequences/Sequence.js:75:24)
at Handshake.ErrorPacket (/Users/sy/nodeTest/node_modules/mysql/lib/protocol/sequences/Handshake.js:69:8)
at Protocol._parsePacket (/Users/sy/nodeTest/node_modules/mysql/lib/protocol/Protocol.js:172:24)
at Parser.write (/Users/sy/nodeTest/node_modules/mysql/lib/protocol/Parser.js:62:12)
at Protocol.write (/Users/sy/nodeTest/node_modules/mysql/lib/protocol/Protocol.js:37:16)
at Socket.ondata (node:internal/streams/readable:1007:22) {
code: 'ERR_UNHANDLED_ERROR',
context: '20/05/2024 10:53:15x1B[31m ERRORx1B[0m caught in mimic.js:socket.on(loadmimic):line 834:n' +
"mySQL connection error: Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)"
}
This is the code that causes and reports the error:
try{
objDBConns[strDBid]['conn'] = mysql.createConnection(objDB);
if ( objDBConns[strDBid]['conn'] ) {
objDBConns[strDBid]['conn'].connect(function(e) {
if ( e ) {
delete objDBConns[strDBid]['conn'];
err.msg({'file' : 'mimic.js',
'method' : 'socket.on('
+ defs.SCKMSG_LOADMIMIC + ')',
'line' : 834,
'ex' : 'mySQL connection error: ' + e,
'socket' : socket});
} else {
info.msg("mySQL connection: ok");
}
});
}
} catch( ex ) {
err.msg({'file' : 'mimic.js',
'method' : 'socket.on(' + defs.SCKMSG_LOADMIMIC + ')',
'ex' : ex,
'socket' : socket});
}
Can anyone suggest what could have changed or why I can connect using MySQLWorkbench but not node.js ?