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

issue with changeUser()

Open parth-b297 opened this issue 10 months ago • 1 comments

I have this service. I recently updated mysql2 version from 2.3.3 to 3.12.0 The db in the production environment is mysql v 5.7.26 eversince then i have problems with changeUser().

lets say that i create a pool

    const pool = mysql.createPool({
      host: hostForReadWrite,
      port: portForReadWrite,
      user: username,
      password: password,
      waitForConnections: true,
      connectionLimit: poolSize,
      debug: true,
      database: dbname
    });
    const promisePool = pool.promise();
    global.proxyConnectionPool = promisePool;
const connection = await global.proxyConnectionPool.getConnection();

the connection works flawlessly

but when i try to change user (the actual reason for this is to switch to and fro between different dbs)

          await connection.changeUser({
            user: username,
            password: password,
            database: dbName
          });

i keep on getting this error

Error: Access denied for user 'username'@'ip' (using password: NO)
    at PromisePoolConnection.changeUser (d:\workspace\node_modules\mysql2\lib\promise\connection.js:160:22)
    at Object.getProxyNodeConnection (d:\workspace\src\crons\setup-sql-connection.js:18:28)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async test (d:\workspace\src\crons\test.js:21:18) {
  code: 'ER_ACCESS_DENIED_ERROR',
  errno: 1045,
  sqlState: '28000',
  sqlMessage: "Access denied for user 'username'@'ip' (using password: NO)"
}

the exact same code used to work fine with mysql2 v 2.3.3

@sidorares @iarna @sushantdhiman @Dieken @wellwelwel

parth-b297 avatar Jan 24 '25 12:01 parth-b297

Hi @parth-b297 would you be able to create self contained repro example / repo?

sidorares avatar Feb 03 '25 22:02 sidorares