Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: connect ECONNREFUSED 127.0.0.1:3306 when using cloud sql for MYSQL from NodeJS app

I followed all the steps mentioned in this sample app link. GitHubLink. When running the script (npm run init-cloudsql) to initialize mysql database, I get an error below:

D:\gcloud\nodejs-getting-started\2-structured-data\books\model-cloudsql.js:143
    throw err;
    ^
Error: connect ECONNREFUSED 127.0.0.1:3306
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
--------------------
at Protocol._enqueue (D:\gcloud\nodejs-getting-started\2-structured- data\node_modules\mysql\lib\protocol\Protocol.js:145:48)                                                                                                          
at Protocol.handshake (D:\gcloud\nodejs-getting-started\2-structured-data\node_modules\mysql\lib\protocol\Protocol.js:52:23)                                                                                                                
at Connection.connect (D:\gcloud\nodejs-getting-started\2-structured-data\node_modules\mysql\lib\Connection.js:130:18)                                                                                                                
at Connection._implyConnect (D:\gcloud\nodejs-getting-started\2-structured-data\node_modules\mysql\lib\Connection.js:461:10)                                                                                                                
at Connection.query (D:\gcloud\nodejs-getting-started\2-structured-data\node_modules\mysql\lib\Connection.js:206:8)                                                                                                               
at createSchema (D:\gcloud\nodejs-getting-started\2-structured-data\books\model-cloudsql.js:126:14)                                                                                                              
at prompt.get (D:\gcloud\nodejs-getting-started\2-structured-data\books\model-cloudsql.js:117:5)                                                                                                              
at D:\gcloud\nodejs-getting-started\2-structured-data\node_modules\prompt\lib\prompt.js:336:32                                                                                                            
at D:\gcloud\nodejs-getting-started\2-structured-data\node_modules\utile\node_modules\async\lib\async.js:154:25                                                                                                            
at assembler (D:\gcloud\nodejs-getting-started\2-structured-data\node_modules\prompt\lib\prompt.js:333:9)  

What am i missing? I could not resolve this error. Can someone help me fix this issue?

like image 274
Mohit Maharjan Avatar asked Aug 07 '26 08:08

Mohit Maharjan


2 Answers

This error occurs when you run an instance of PopSQL or Node.js and the MySQL server is not running on your local machine. Try the below steps

  1. Press Windows key and R on your keyboard. This opens the command prompt
  2. Type in services.msc and click ok.
  3. In the services pop up , check for MYSQL57. If its not in the running state, Click on run this service in the left column of the dialog box
  4. Once the service is running connect to the POPSQL from the connections window
like image 86
user14315555 Avatar answered Aug 08 '26 21:08

user14315555


The error message you shared indicates your machine could not connect to the instance's IP address on port 3307 (which is used by the proxy). I tested this on my own machine, and it is listening there. This likely indicates a firewall on your machine or your local network that is preventing outbound connections on port 3307. Try and open this in the firewall, and see if you can connect.

like image 44
David Avatar answered Aug 08 '26 21:08

David