NodeJS mysql module transforms localhost to 127.0.0.1 and fails connection
See original GitHub issueI 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:
- Created 4 years ago
- Comments:19 (10 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
SOLVED! Thanks to this SO question - https://stackoverflow.com/a/50131831/919480
Two things.
mysql_native_password
. I think, this is related to the choice of option ‘Strong Password’ when installing MySQL.host
parameter should not belocalhost
because on Unix, it is treated differently. That is, the connection is via a socket (as you mentioned earlier). Therefore, sethost
parameter to127.0.0.1
. Or, removehost
parameter and usesocketPath
.Basically, let me know what the result of running the following command is on your setup when you have a chance: