0

Without using my .env file it work but when I used to create a connection it fails.

var mysql = require('mysql');
require('dotenv').config();

const db = mysql.createConnection({
    host: process.env.HOST,
    port: "3306",
    user: process.env.USER,
    password: process.env.PASSWORD,
    database: process.env.DATABASE
});
module.exports = db

I have this error.

error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

But I'm already up-to-date with the last mysql version.

Any idea ?

I tried already this, but it didn't work too even if I can run those commands.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
flush privileges;
  • Does this answer your question? [MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client](https://stackoverflow.com/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server) – OFRBG Feb 04 '22 at 23:56
  • No, I tried it but it's a different issue – Alexandre Cardin Feb 05 '22 at 00:08

2 Answers2

1

Sometimes are the names of the variables in the .env file the real problem... this is what i use:

require("dotenv").config();
const util = require("util");

var mysql = require("mysql");
const conn = {
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASS,
  database: process.env.DB_NAME,
};
const db = = mysql.createConnection(conn);
module.exports = db

cgarciagl
  • 41
  • 4
0

I founded out ! process.env look in the system first before my .env file. USER is already declared, so it returns me my username of my computer. I just needed to alter the name of user variable, and it worked fine

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 05 '22 at 03:22