Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell node.js that mysql is not running on default port?

I'm having a problem similar to this person's: connect ECONNREFUSED - node js , sql

I'm trying to connect app.js to an existing database running as part of MAMP. MAMP runs mysql on port 8889; how do I tell node.js which port to find mysql on?

like image 934
ario Avatar asked Jan 28 '12 00:01

ario


2 Answers

When you are initializing the mysql client, along with username and password, you can pass a different value for port.

const client = mysql.createClient({
  user: '??',
  password: '??',
  port: 8889
});
like image 97
loganfsmyth Avatar answered Oct 11 '22 15:10

loganfsmyth


For those initializing the mysql connection object using mysql.createPool({...}), it's the same solution as the accepted answer. For Reference

   const connection = mysql.createPool({
      host: ...,
      port: 8889,
      user: ...,
      password: ...,
    });
like image 43
VillageSavers Avatar answered Oct 11 '22 15:10

VillageSavers