sidorares / sidorares/node-mysql2

issue with changeUser()

Open
#3,350 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs investigation
Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/crons/setup-sql-connection.js and the call at lib/promise/connection.js:160, then reproduce the reported changeUser() failure against MySQL 5.7.26 using mysql2 2.3.3 and 3.12.0. Compare the behavior and error details; done means the documented changeUser() call no longer reports that the password was omitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, nodejs, typescript
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
43/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.