node-mysql2: [question RE: proxy example] unable to select database

Hi. Great library!

The following output is produced by a proxy server which uses your wonderful library as both a server and a client (to a remote MariaDB database).

This test fully confirms that the observed behavior isn’t the result of anything that I added, since the same occurs in the proxy server example as taken directly from your repo.

Example from the mysql command-line client connected to the proxy:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: mysql-proxy mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| mysql_proxy_test   |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.005 sec)

MySQL [(none)]> use mysql_proxy_test;
Database changed
MySQL [mysql_proxy_test]> select database();
+------------+
| database() |
+------------+
| NULL       |
+------------+
1 row in set (0.014 sec)

MySQL [mysql_proxy_test]> show tables;
ERROR 1064 (_____): No database selected
MySQL [mysql_proxy_test]>

The fundamental issue is how the mysql client executes “USE db_name;” statements. Apparently, this command isn’t sent to the proxy and, consequently, is not forwarded to the remote db connection. Instead, this connection sees: “SELECT DATABASE()”.

I can fully confirm that when the “USE db_name;” query is directly passed to the remote db connection… it works. The problem is that the mysql client doesn’t communicate this query.

Do you think this is a bug in the mysql client?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 22 (22 by maintainers)

Commits related to this issue

Most upvoted comments

not a problem… my project is just a proof-of-concept for right now… nothing mission critical. I’ll try to write a monkey patch for until it hits npm.

awesome!

after applying that fix… I retested:

  conn.on('init_db', (schemaName) => {
    conn.emit('query', `USE ${schemaName};`)
  })

…and now “USE db_name;” statements work in the mysql client

notes:

  • in spite of connection.clientHelloReply.encoding having the value 'cp850' immediately after the handshake completes, the value is (for some unknown reason) undefined when accessed in the above switch statement.
  • same result if I assign a static value in the authCallback hook function: conn.clientHelloReply.encoding = 'utf8'

now:

  • I’ll do as you suggest, and hard code the value inside the library… just to test whether it would work if encoding wasn’t getting in the way…