question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NodeJS mysql module transforms localhost to 127.0.0.1 and fails connection

See original GitHub issue

I am trying to connect to ProxySQL that is set-up to connect to a MySQL database. From command line, the following works. The port number 6033 is for ProxySQL.

mysql -u demo1 -P6033 --database=database -p

However, the connection to ProxySQL with this package does not work.

var connection = mysql.createConnection({
        "host" : "localhost",
        "port": 6033,
        "user": "demo1",
        "password" : "password",
        "database": "database"
    })
 connection.connect( (err) => { console.log(err.stack) } )

This is the error message.

Error: ER_ACCESS_DENIED_ERROR: ProxySQL Error: Access denied for user 'demo1'@'127.0.0.1' (using password: YES)

The user was created as

CREATE USER 'demo1'@'localhost' IDENTIFIED BY 'password';

I tried adding another user as 'demo'@'127.0.0.1' and granted privileges for the same; didn’t work.

How do I retain the definition above and get mysql to return a successful connection?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
chainheadcommented, Jul 24, 2019

SOLVED! Thanks to this SO question - https://stackoverflow.com/a/50131831/919480

Two things.

  1. MySQL has to be told to use mysql_native_password. I think, this is related to the choice of option ‘Strong Password’ when installing MySQL.
  2. The host parameter should not be localhost because on Unix, it is treated differently. That is, the connection is via a socket (as you mentioned earlier). Therefore, set host parameter to 127.0.0.1. Or, remove host parameter and use socketPath.
1reaction
dougwilsoncommented, Jul 24, 2019

Basically, let me know what the result of running the following command is on your setup when you have a chance:

mysql -u demo1 --protocol=TCP -P6033 --database=database -p
Read more comments on GitHub >

github_iconTop Results From Across the Web

NodeJS mysql module transforms localhost to 127.0.0.1 and ...
This is the error message. CREATE USER 'demo1'@'localhost' IDENTIFIED BY 'password'; I tried adding another user as 'demo'@'127.0. 0.1' and ...
Read more >
connect ECONNREFUSED 127.0.0.1:3306 solved in Node JS ...
How to fix Error : connect ECONNREFUSED 127.0.0.1 :3306 in node js and mysql is shown.
Read more >
How to Fix Failed to Connect to MySQL at 127.0.0.1 With User ...
How to Fix Failed to Connect to MySQL at 127.0.0.1 With User Root Windows 10 / 8 / 7 Error Workbench. 52K views...
Read more >
Localhost Refused to Connect Error: 5 Confirmed Ways to Fix It
Localhost refused to connect error can be caused by an incorrectly configured port, insufficient permissions, or an inoperative web server.
Read more >
MySQL 8.0 Reference Manual :: 5.1.8 Server System Variables
If the address is a “regular” IPv4 or IPv6 address (such as 127.0.0.1 or ::1 ), the server accepts TCP/IP connections only for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found