I am trying to fetch data from a MySQL table. It works perfectly when I hardcode the configuration. But when I use env variables to configure it, I get the following error:
code: 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251,
sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client',
sqlState: '08004',
fatal: true
This is my .env.local file:
MYSQL_HOST: localhost
MYSQL_USER: root
MYSQL_PASSWORD:************
MYSQL_DB:***
this is my db connections code:
const mysql = require("mysql");
var db = mysql.createConnection({
host: process.env.MYSQL_HOST,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DB,
});
db.connect((err) => {
if (err) {
console.log(err);
} else {
console.log("connected to db");
}
});
module.exports = db;