Re: No Node.js Access To MySQL Community Database . . .
Hi Kon,
looks like you are using the "mysql" npm package, which, contrary to Connector/Node.js (the "@mysql/xdevapi" package) is a community driven project, not maintained by MySQL and/or Oracle. Any concern related to that package should be addressed in the project issue tracker on GitHub (https://github.com/mysqljs/mysql).
In any case, I would say the problem is that you are incorrectly using "conn.connect()". As far as I know, the API method accepts a single argument, which is a callback with a single error parameter, that lets you know if the connection failed or not. You are passing an extra "query" parameter, and the callback signature itself is not correct.
What you want is the following:
conn.connect(errconn => {
if (errconn) {
console.error('Error connecting: ' + errconn.stack);
dbCallback(errconn, null, null);
} else {
console.log('Connected as id ' + connection.threadId);
dbCallback();
}
});
However, as far as I know, the "mysql" npm package does not work out-of-the-box with MySQL 8.0, because by default, the server uses the "caching_sha2_password" authentication plugin, which is not supported by that specific client implementation.
https://stackoverflow.com/a/50377944/3235909
So you will probably not be able to connect anyway. If that is the case, I suggest you use the "@mysql/xdevapi" npm package (https://www.npmjs.com/package/@mysql/xdevapi), which is the official MySQL connector for Node.js.
Hope it helps.
Thanks