I’m having trouble connecting to my MySQL 8.0 database from a Node.js app. I’ve set up the latest MySQL Community 8.0 and Node.js with default settings, but I keep getting an error.
Here’s my Node.js code:
const db = require('mysql');
const connection = db.createConnection({
host: 'localhost',
user: 'root',
password: 'mypassword',
insecureAuth: true
});
connection.connect((error) => {
if (error) {
console.error('Connection failed:', error);
} else {
console.log('Connected successfully!');
}
});
When I run this, I get an error saying the client doesn’t support the authentication protocol. It suggests upgrading the MySQL client, but I’m already using the latest version.
I’ve looked at some docs and GitHub issues, but I’m still stumped. Any ideas on how to fix this? Is there something I’m missing in my setup or code?