node-mysql2
node-mysql2 copied to clipboard
Cannot read property 'slice' of undefined
const mysql = require("mysql2/promise");
var mpool = mysql.createPool({
connectionLimit: 10,
host: process.env.MYSQL_IP,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DB,
});
async function getSomething() {
const [rows, fields] = await mpool.execute(
`select query`
);
console.log(rows);
}
query never runs and outputs this error below. isql is working with same login settings:
node_modules/mysql2/lib/auth_41.js:78 const authPluginData2 = scramble2.slice(0, 12);
^
TypeError: Cannot read property 'slice' of undefined at Object.exports.calculateTokenFromPasswordSha (node_modules/mysql2/lib/auth_41.js:78:37) at Object.token [as calculateToken] (node_modules/mysql2/lib/auth_41.js:68:18) at new HandshakeResponse (node_modules/mysql2/lib/packets/handshake_response.js:28:26) at ClientHandshake.sendCredentials (node_modules/mysql2/lib/commands/client_handshake.js:52:31) at ClientHandshake.handshakeInit (node_modules/mysql2/lib/commands/client_handshake.js:137:12) at ClientHandshake.execute (node_modules/mysql2/lib/commands/command.js:39:22) at PoolConnection.handlePacket (/node_modules/mysql2/lib/connection.js:425:32) at PacketParser.onPacket (node_modules/mysql2/lib/connection.js:75:12) at PacketParser.executeStart (node_modules/mysql2/lib/packet_parser.js:75:16) at Socket.
(node_modules/mysql2/lib/connection.js:82:25)
looks like this code is never reached to set authPluginData2
Can you show what's plugin / auth method configured for MYSQL_USER user? From admin user isql - SELECT plugin from mysql.user where User="[insert MYSQL_USER here]";
[S0022][MySQL][ODBC 3.51 Driver][mysqld-4.0.20a-nt]Unknown column 'plugin' in 'field list'
can you show everything? SELECT * from mysql.user .... Also could you check what version of mysql server you have
version: 4.0.20a-nt
this is a very old db, I could only connecti via 3.51 odbc drivers from my pc.
output of select * from mysql.user

looks like server requires pre-4.1 auth method which is currently not supported. I'd really like to handle that better but actual support for old auth method might never land here, if you absolutely need connecting to this db without upgrading it the easiest way would be to switch to mysqljs/mysql driver.
some links to help with future me ( or someone else ) to implement old auth:
https://dev.mysql.com/doc/internals/en/old-password-authentication.html https://github.com/mysqljs/mysql/blob/3430c513d6b0ca279fb7c79b210c9301e9315658/lib/protocol/Auth.js https://github.com/mysqljs/mysql/blob/c144ddacb0fd7f5b65e02f227cd149a52dedfb36/lib/protocol/sequences/Handshake.js#L97
( would be good to find docker images for ancient mysql server version )
@sidorares mysql 4.1 is really archaic. Should we still support that?
we don't have to support every old server version, but I think good behaving driver should not 1) crash when server version is not supported 2) return good error explaining what happened and how to fix
re particular version ( 4.1 and older ) - not sure how many people use it. I'd say not enough to justify dev effort but don't have evidence to support. There is always drop in mysqljs/mysql replacement for those who must use old server
For something that was released 17 years ago, I would say not a lot 😂
I just spent three hours googling this - to land here.
PRs welcome to add better error message for old auth plugins?
Yes, improving error messaging here would be very welcomed @seebeen