Giesburts
Giesburts

Reputation: 7628

Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

So I am working with Loopback (Node.js framework) for the first time and I tried to set up a Mysql model. I've installed Loopback globally, and also installed the mysql connector with npm. After that, I tried to add a datasource with the mysql connector. I tried to use my MAMP localhost database.

Unfortunatly I get an error when I try to connect with loopback again typing the node . command. The error: Error: connect ECONNREFUSED 127.0.0.1:3306.

So I did some research and many people answered on different node questions saying you have to add the socket of MAMP to your config in order to get a connection. So I tried to add that but that doesn't seem to work or I am not doing it right, because, I can't find the proper way of doing it. Here is my datasource:

  "db": {
    "host": "127.0.0.1",
    "port": "3306",
    "url": "",
    "database": "meetups",
    "password": "root",
    "name": "root",
    "user": "root",
    "connector": "mysql"
  }

And I tried to add "socketPath": "/var/run/mysqld/mysqld.sock" and "socket": "/var/run/mysqld/mysqld.sock" but that doesn't seem to work. Is there anybody out there with exp. in node.js / loopback?

Upvotes: 4

Views: 3575

Answers (2)

Giesburts
Giesburts

Reputation: 7628

After researching the Loopback MySQL docs I have found out that you can use additional parameters supported by node-mysql, that's located here.

At the Connection options I found socketPath. So that's actually the parameter for socket when using MAMP. After using that, and also removing the url parameter, the connection worked with this:

  "db": {
    "host": "127.0.0.1",
    "port": 3306,
    "database": "meetups",
    "password": "root",
    "name": "db",
    "user": "root",
    "connector": "mysql",
    "socketPath": "/Applications/MAMP/tmp/mysql/mysql.sock"
  }

The only problem I got after was something with the database tables. I had to autoimigrate them for some reason, don't exactly knew what that was but I found the solution over here. I tried the Grunt automigrate task and now my loopback backend with MySQL works fine so far.

Upvotes: 5

Mark Ryan Orosa
Mark Ryan Orosa

Reputation: 867

This is my working datasource mysql setup:

"voipnow": { //should equal the name param
    "host": "localhost",
    "port": 3306,
    "database": "databasename",
    "username": "root",
    "password": "root",
    "name": "voipnow",
    "connector": "mysql",
    "namingStrategy": "underscore"
  },

The name should match the declared datasource name

Upvotes: 0

Related Questions