node-mysql2 icon indicating copy to clipboard operation
node-mysql2 copied to clipboard

Cannot read property 'slice' of undefined

Open fuzunspm opened this issue 5 years ago • 11 comments

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)

fuzunspm avatar Nov 03 '20 19:11 fuzunspm

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]";

sidorares avatar Nov 03 '20 21:11 sidorares

[S0022][MySQL][ODBC 3.51 Driver][mysqld-4.0.20a-nt]Unknown column 'plugin' in 'field list'

fuzunspm avatar Nov 04 '20 06:11 fuzunspm

can you show everything? SELECT * from mysql.user .... Also could you check what version of mysql server you have

sidorares avatar Nov 04 '20 06:11 sidorares

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

Screen Shot 2020-11-04 at 9 15 06 AM

fuzunspm avatar Nov 04 '20 06:11 fuzunspm

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.

sidorares avatar Nov 04 '20 22:11 sidorares

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 avatar Nov 04 '20 23:11 sidorares

@sidorares mysql 4.1 is really archaic. Should we still support that?

testn avatar Nov 09 '21 17:11 testn

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

sidorares avatar Nov 10 '21 01:11 sidorares

For something that was released 17 years ago, I would say not a lot 😂

testn avatar Nov 10 '21 01:11 testn

image

I just spent three hours googling this - to land here.

PRs welcome to add better error message for old auth plugins?

seebeen avatar Feb 06 '24 16:02 seebeen

Yes, improving error messaging here would be very welcomed @seebeen

sidorares avatar Feb 10 '24 01:02 sidorares