PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 14, 2022

[FIXED] Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

 March 14, 2022     loopback, loopbackjs, mamp, node.js     No comments   

Issue

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?


Solution

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.



Answered By - Giesburts
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing