MySQL Forums
Forum List  »  Connector/Node.js

Re: No Node.js Access To MySQL Community Database . . .
Posted by: Rui Quelhas
Date: November 26, 2021 12:28PM

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

Options: ReplyQuote


Subject
Written By
Posted
Re: No Node.js Access To MySQL Community Database . . .
November 26, 2021 12:28PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.