Mysql: ER_ACCESS_DENIED_ERROR:

Created on 14 Sep 2013  路  9Comments  路  Source: mysqljs/mysql

Am sure this has already been sorted out but couldn't find anything conclusive.

I am specifying the database credentials when I create the mysql.createConnection

While connecting to the db it gives with this error Access denied for user \'root\'@\'triband**.mtnl.net.in\' (using password: YES)'

I am 100 % sure these are not the credentials for the database. How do I solve this ?

question

Most helpful comment

Upgrade the package version to ^2.1.x solved my problem.

All 9 comments

Most likely this issue is that in the database the root user is only allowed to connect from the "localhost".. You need to update it to allow that user to connect from any host or to be safer only from the host you know (triband....)

The instructions are here http://dev.mysql.com/doc/refman/5.5/en/adding-users.html

Thanks tolgaek. This worked for me.

I have this issue even though I have these permissions:

mysql> show grants;
+-------------------------------------------------------------------------------------------------------------+
| Grants for RollingRidge@%                                                                                   |
+-------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'RollingRidge'@'%' IDENTIFIED BY PASSWORD '*REDACTED'                                 |
| GRANT ALL PRIVILEGES ON `rollingridge`.* TO 'RollingRidge'@'%'                                              |
+-------------------------------------------------------------------------------------------------------------+

hey team, i know it's been a while on this issue, but i'm seeing a problem like this. I'm getting:

Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'myuser '@'localhost' (using password: YES)

when i run my node script from root (su sudo on ubuntu 14.04) the script works when i run as myuser (anyway it explicitly tells node-mysql to use myuser)

Hi @thegreatmichael

grant entries are separate for local domain socket and tcp connections, when you connect from command line you are likely do it via domain socket ( you can locate it with mysql_config --socket command ) so the solution is to either 1) add grant entry for 'localhost' or 2) connect using socket - see socketPath connection option

thanks for the quick response @sidorares ! I'm slightly confused, probably because I provided too little info. see below:

mysql> mysqlgrants;
+---------------------------------------------------------------------------+
| Grants for myuser@localhost                                               |
+---------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'myuser'@'localhost' IDENTIFIED BY PASSWORD <secret>|
| GRANT ALL PRIVILEGES ON `somedbdev`.* TO 'myuser'@'localhost'             |
| GRANT ALL PRIVILEGES ON `somedbprod`.* TO 'myuser'@'localhost'            |
+---------------------------------------------------------------------------+

So, I think i have allowed the user the permission on localhost, should that work?

To be clear:

myuser@mymachine:~somepath$ node myscript.js 

^works! (-: ^

myuser@mymachine:~somepath$ sudo su
root@mymachine:/home/myuser/somepath# node myscript.js 

/home/myuser/somepath/myscript.js:462
      if(err) throw err;
                    ^
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'myuser '@'localhost' (using password: YES)

^ doesn't work )-: ^

Hi @thegreatmichael, perhaps when you run it as root, it is accessing some different configuration file or something? The error is that the login failed for the user 'myuser ', where there is a space character at the end of the username. I assume you user does not actually have a space, so there is some kind of thing happening in your code adding a space at the end of your username it seems. Try attaching a debugger to your code to see where it is coming from.

thanks @dougwilson YOU GLORIOUS CHAMPION! you are a golden god. indeed, i was originally running with env vars on the command line

env1=something env2=else node script.js

but when i copied that to change it into individual lines, i didn't remove the (not so visible in my editor) trailing spaces!

(It's working)

Upgrade the package version to ^2.1.x solved my problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Rhapsody-Sky picture Rhapsody-Sky  路  3Comments

nanom1t picture nanom1t  路  3Comments

PeppeL-G picture PeppeL-G  路  3Comments

abou7mied picture abou7mied  路  4Comments

Axxxx0n picture Axxxx0n  路  3Comments