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;
CodePudding user response:
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
CodePudding user response:
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
