Reputation: 1069
I'm trying to connect remote server MySQL database from another test server from my rest API using node js.
My database connection.js
var mysql = require('mysql');
var poolConnection = mysql.createPool({
connectionLimit : 100,
host : 'xx.xx.xx.xxx',
port : 3306,
user : 'testuser',
password : 'test123',
socketPath : '/var/run/mysqld/mysqld.sock'
});
exports.query = function(sql,args,callback){
poolConnection.query(sql,args,callback);
}
While trying to run the query from my API I'm getting this error :
{ Error: connect ENOENT /var/run/mysqld/mysqld.sock
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
----------------------------
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'connect',
address: '/var/run/mysqld/mysqld.sock',
fatal: true }
From many another StackOverflow reference, I also try to comment out bind-address but there is also not any success. How to solve this problem.
Upvotes: 1
Views: 2273
Reputation: 203231
For connections to a remote MySQL server, leave out the socketPath
option, because that only makes sense if the MySQL server is running on the same host as your application.
This does require that the MySQL server is set up to allow connections over TCP.
Upvotes: 2