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

Mohit Maharjan picture Mohit Maharjan · Oct 8, 2017 · Viewed 8k times · Source

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?

Answer

David picture David · Oct 9, 2017

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.