1

I've tried following the suggestion at this link: MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

and am aware that it is using cahcing_sha2_password instead of mysql_native. However, I've tried following the suggestions and am still receiving the same errors, trying to connect to the database with node.

Schema name: 'my_db'

//DATABASE CONNECTION SETTINGS
const APIServerPort = 3001;

const database = {
  host: "localhost",
  port: 3306,
  user: "root",
  password: "xxx",
  database: "my_db"
};

module.exports = {
  database,
  APIServerPort
};

app.js file:

const express = require("express");
const app = express();
const router = express.Router();
const settings = require("./settings");
const routes = require("./routes");
const mysql = require("mysql");

const connection = mysql.createConnection(settings.database);

router.get("/employees", routes.employees.listAllEmployees);

app.use("/apis", router);

connection.connect(error => {
  if (error) {
    console.error("Error Connecting to the database: " + error);
    return process.exit();
  }

  app.listen(settings.APIServerPort, () =>
    console.info(`Server is running at port ${settings.APIServerPort}...`)
  );
});

SQL Queries Ran:

CREATE USER 'root'@'localhost:3301/apis/employees' IDENTIFIED WITH mysql_native_password BY 'xxx';
FLUSH PRIVILEGES;

I'm still receiving the same error however.

DreamVision2017
  • 372
  • 1
  • 9
  • 23

1 Answers1

-2

mysql users are in the form 'root'@'localhost'. Urls are a node.js concept only.

As that user already exists create a new one:

CREATE USER myapplication@localhost
  IDENTIFIED WITH mysql_native_password BY 'xxx';
GRANT ALL ON my_db.* TO myapplication@localhost`;

You don't need FLUSH PRIVILEGES.

danblack
  • 12,130
  • 2
  • 22
  • 41