0

I've seen many variations of this question, but I couldn't find an answer - and in fact am not sure where to look for logs that could help me. Here's the situation.

I was following this tutorial

I have the following in a file called "server.js":

const mysql = require("mysql");
const express = require("express");
const bodyParser = require("body-parser");

var app = express();

app.use(bodyParser.json());

var mysqlConnection = mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "confidential666!",
    database: "blunt",
    multipleStatements: true
});

mysqlConnection.connect((err)=>{
    if(!err){
    console.log("Connected");
        }
    else{
        console.log("connect failed");
        console.log("big woof");

    }
});

app.listen(3000);
console.log("did run");

I run this code with "nodemon server.js"

However, my console shows me "connect failed" and "big woof".

I then tried to connect to my database with mysql.exe with the same credentials, and could connect to "blunt" just fine.

Port is missing from my connection, but documentation suggests 3306 is the default and that's what my server is using. Adding it made no difference. Any idea on how I can figure out why I can't get my nodemon to connect to my database?

  • 1
    Have you tried logging the error from your mysql.Connection.connect line? The else is logging the 'connect failed', and 'big woof', which means there's an error being passed to the err – gbac Dec 20 '21 at 01:56
  • @gbac - Oh, duh. Sorry, I haven't done any development in a long while. I get ``` code: 'ER_NOT_SUPPORTED_AUTH_MODE', errno: 1251, sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client', ``` Is it possible the mysql client being run by my program is 5...? I did see an option when I installed MySQL / Workbench about allowing legacy connections. – Kaspar Hauser Dec 20 '21 at 02:36
  • 1
    Hard to tell from here, maybe you will find your solution [in this post](https://stackoverflow.com/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server). – gbac Dec 20 '21 at 02:49
  • I have no idea why, but this worked! Thank you. Do you have any idea why? – Kaspar Hauser Dec 20 '21 at 03:43
  • 1
    Updates to MySQL authentication methods that aren't supported by the node package yet.. [This post](https://stackoverflow.com/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server/56509065#56509065) explains it pretty well – gbac Dec 20 '21 at 03:51
  • Run `SELECT version();` to check exact MySQL version. – FanoFN Dec 20 '21 at 06:13

0 Answers0