I'm trying to connect to a MySQL database with Node.JS and at first, it works. Then, kinda at random, it gives the following error:
Error: connect ECONNREFUSED 127.0.0.1:3306
at Object._errnoException (util.js:1031:13)
at _exceptionWithHostPort (util.js:1052:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1195:14)
--------------------
at Protocol._enqueue (/root/Geola/node_modules/mysql/lib/protocol/Protocol.js:145:48)
at Protocol.handshake (/root/Geola/node_modules/mysql/lib/protocol/Protocol.js:52:23)
at Connection.connect (/root/Geola/node_modules/mysql/lib/Connection.js:130:18)
at Object.<anonymous> (/root/Geola/runMain.js:24:12)
at Module._compile (module.js:641:30)
at Object.Module._extensions..js (module.js:652:10)
at Module.load (module.js:560:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)
at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:73:21)
I double-checked that the port is correct by using the command netstat -tlnp
and got back tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 25362/mysqld
That seems to be correct so I restart the Node.JS app and everything works again... until again, at random, the error pops up again. I tested if it errors only when I try to interact with the database and I found that it does indeed spit out this error at random. Sometimes I can interact with the DB just fine and sometimes I can't. I find this error quite odd so if anyone knows the issue, please do let me know. Thanks!
Ok I found the answer. It was simply that Digital Ocean, the database hoster, had a limit on how much data could be sent at once