1

So I'm trying to transition away from using xampp and using mysql workbench. I started up a local db connection and managed to successfully connect to it in my local environment through workbench. However, In my NodeJS file, I'm trying to connect to this local database instance but in my terminal, the condition statement is failing saying it's unsuccessful connecting to the local mysql instance and I'm not sure why.

local db workbench configuration:

user: root
password: (cant say but its my own password)
port: 3306
host: localhost

Screenshot of the service running:

enter image description here

NodeJS Code

var mysql = require("mysql");

var connection = mysql.createConnection({
  host: "localhost",
  user: "root",
  password: "mydbpasswordishere",
  database: "testdb",
  port: 3306,
  charset: "utf8mb4"
});

connection.connect(err => {
  if (!err) {
    console.log("DB Connection Succeeded");
  } else {
    console.log("DB Connection Failed");
  }
});

module.exports = connection;
Jorden
  • 153
  • 1
  • 3
  • 16
  • what does NodeJS report the error as? – danblack Feb 06 '19 at 06:57
  • `DB Connection Failed`. I can connect just fine through the local workbench but when i try to connect to it through nodejs the condition that checks the connection to the local db instance fails. When i log the `err` it returns `ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client` – Jorden Feb 06 '19 at 07:00
  • Figured it out after a couple hours of looking around had to go into workbench and run the following query: `ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'` – Jorden Feb 06 '19 at 07:13
  • 2
    Correct. The node.js mysql driver you are using does not support the default authentication plugin used on MySQL 8, so you can work around that by switching to old plugin - `mysql_native_password`. More details available [here](https://stackoverflow.com/a/50377944/3235909). – ruiquelhas Feb 06 '19 at 09:15

1 Answers1

0

As per your screenshot: You have interchanges the name and hostname of your connection. Either change in your nodeJS code or edit the connection in workbench. It should work.

Bush
  • 261
  • 1
  • 11