Skip to content

ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO) #2142

Closed
@henaege

Description

@henaege

Hello,

I have a node app that uses a mysql database (Server version: 5.7.24-0ubuntu0.16.04.1 (Ubuntu)). It used to work fine but just recently I get the ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO) error when running the app. I see afew other similar issues reported but they don't seem to be the same.

Here is my javascript:

function handleDisconnect() {
    var connection = mysql.createConnection({
        host: 'localhost',
        user: 'x',
        password: 'password',
        database: 'database_name'
}) 

connection.connect(function(err) {              
    if(err) {                                     
      console.log('error when connecting to db:', err);
      setTimeout(handleDisconnect, 2000);
    }                                     
  });                                     
                                         
  connection.on('error', function(err) {
    console.log('db error', err);
    if(err.code === 'PROTOCOL_CONNECTION_LOST') { 
      handleDisconnect();                         
    } else {                                      
      throw err;                                  
    }
  });
}

I can log in to the mysql server just fine on CLI. The issue appears to be that for whatever reason the user name and password aren't being used by mysql (Access denied for user ''@'localhost' (using password: NO)) even though they are specified above. I don't have an anonymous ('') user listed, which I think would cause the ''@'localhost' if that were the case?

mysql> select user, host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| debian-sys-maint | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
| x                | localhost |
+------------------+-----------+
5 rows in set (0.00 sec)

So why is mysql apparently looking for an anonymous user and not recognizing the password parameter? Please let me know what additional information you may need. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions