1

I'm getting this error when I try to use dotenv

ERROR: Host 'DESKTOP-I4V1RGG' is not allowed to connect to this MySQL server

for some reason, the HOSTNAME is being read as the name of my computer and not as 'localhost' as I defined in the .env

This is my config.js:

require('dotenv').config();

    module.exports = {
    
      development: {
    
        username: process.env.MYSQL_USER,
    
        password: process.env.MYSQL_PASSWORD,
    
        database: 'database_name',
    
        host: process.env.HOSTNAME,
    
        dialect: 'mysql',
    
      },
    
    };

and this is my .env:

JWT_SECRET=hardcoded_secret

MYSQL_USER=root

MYSQL_PASSWORD=1234

HOSTNAME=localhost

I think this may have something to do with Windows environment variables. Any guess?

ps: I'm a newbie. Please be kind.

---- edit: I changed the variable name from HOSTNAME to MYCOMPUTER, and it works perfectly. The problem is the word HOSTNAME that instead of looking for what I set in the .env, it looks in some Windows configuration. This happens quite often since I switched to Windows OS.

  • Does this answer your question? [Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server](https://stackoverflow.com/questions/1559955/host-xxx-xx-xxx-xxx-is-not-allowed-to-connect-to-this-mysql-server) – Sercan Dec 16 '21 at 20:08
  • @SercanSebetçi hey! Unfortunately not – brunacamposxx Dec 16 '21 at 20:12
  • I changed the variable name from HOSTNAME to MYCOMPUTER, and it works perfectly. The problem is the word HOSTNAME that instead of looking for what I set in the .env, it looks in some Windows configuration. This happens quite often since I switched to Windows OS. – brunacamposxx Dec 16 '21 at 20:19
  • Same thing happened to me with USERNAME. dotenv.config() added other variables to the environment, but left USERNAME as Windows defined it. And threw no error, so the failure was silent. Must be because I did not set the override option to true. – Jonathan Pool Apr 05 '22 at 21:17

0 Answers0