Reputation: 490
First of all, I can't find any answers here and Google. I may search the wrong direction and appreciate any help.
Node: 10.24.1/12.22.1/14.17.0/16.3.0 (These are the versions I tried)
Mysql for node: 2.18.1
Knex: 0.95.0/0.95.4/0.95.5 (Versions I tried)
Test environments: two computers (mac & win) in two networks (totally separated)
Background
The code needs to access the mysql database locally. This database has been tested through HeidiSQL(win) and Sequel Ace(mac) on those two computers with the same credentials remotely and successfully.
To avoid interference by other codes, I initiated a new project using npm init
. It has one file: app.js
and the code is below:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '123.123.123.123', // Remote database IP
user : 'user_name',
password : 'pass',
database : 'mydb'
});
connection.connect();
connection.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
if (error) throw error;
console.log('The solution is: ', results[0].solution);
});
connection.end();
200.200.200.200
here is an example of the network's real IP
And the error is below:
code: 'ER_ACCESS_DENIED_ERROR',
sqlMessage: "Access denied for user 'user_name'@'200.200.200.200' (using password: YES)",
sqlState: '28000',
fatal: true
I then clone this mini test project to another computer and tested in a different network with example IP 202.202.202.202
and the error is below:
code: 'ER_ACCESS_DENIED_ERROR',
sqlMessage: "Access denied for user 'user_name'@'202.202.202.202' (using password: YES)",
sqlState: '28000',
fatal: true
Apparently the username has been adapted by the mysql library but the host is not. I assume that the password is taken in as well. because of the using password: YES
.
I don't think this is related to the database because without using the correct IP, the code hasn't even touched the database server yet.
It looks like it's using localhost
but shouldn't it be 192.168.x.x
and I don't use localhost
anywhere.
I tried a few versions of node and looks like it's not related to node. knex
and mysql
are freshly installed using npm
. Project is as clean as possible. I can't anywhere that has any problems could cause this.
Any help is appreciated.
Upvotes: 0
Views: 229
Reputation: 114
Check your database username and password. If it's working before then it should work now and I don't think it's related to node of any of your dependancies.
If it's never working, then try to change your password and try again. From your example the config is used by the mysql lib so there's no reason it picks your username and password but explicitly ignores your host.
Upvotes: 2