0

Update: This fixed the problem! Turns out I forgot to unbind MySQL localhost address only.

I'm trying to connect to a MySQL server that is running in the same network but a different IP address from another device. Connection from localhost works.

var connection = mysql.createConnection({
  host     : '172.16.3.170',
  port     : 3306,
  user     : 'root',
  password : '',
  database : 'owen_pm'
});

Error:

{ Error: connect ECONNREFUSED 172.16.3.170:3306
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
    --------------------
    at Protocol._enqueue (/home/pi/pmsensor/node_modules/mysql/lib/protocol/Protocol.js:141:48)
    at Protocol.handshake (/home/pi/pmsensor/node_modules/mysql/lib/protocol/Protocol.js:52:41)
    at Connection.connect (/home/pi/pmsensor/node_modules/mysql/lib/Connection.js:130:18)
    at query (/home/pi/pmsensor/test.js:50:14)
    at Object.<anonymous> (/home/pi/pmsensor/test.js:86:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '172.16.3.170',
  port: 3306,
  fatal: true }

Output of "ps ax | grep mysqld"

  638 ?        S      0:00 /bin/sh /usr/bin/mysqld_safe
 1008 ?        Sl   1416:57 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib/mysql/plugin --user=mysql --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
 3759 pts/0    S+     0:00 grep --color=auto mysqld

Thanks in advance!

Update: This fixed the problem! Turns out I forgot to unbind MySQL localhost address only.

owenhu99
  • 31
  • 5

0 Answers0