0

I used to run mysql using xampp, do I have to run mysql service?

I followed this tutorial -> http://mfikri.com/en/blog/nodejs-mysql-crud

I'm confused in step #2

        Server is running at port 8000
/home/aziz/Desktop/Myprojects/backend/crud_fikri/crud-nodejs-mysql/index.js:23
  if(err) throw err;
          ^

Error: connect ECONNREFUSED 127.0.0.1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1136:16)
    --------------------
    at Protocol._enqueue (/home/aziz/Desktop/Myprojects/backend/crud_fikri/crud-nodejs-mysql/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/home/aziz/Desktop/Myprojects/backend/crud_fikri/crud-nodejs-mysql/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at Connection.connect (/home/aziz/Desktop/Myprojects/backend/crud_fikri/crud-nodejs-mysql/node_modules/mysql/lib/Connection.js:118:18)
    at Object.<anonymous> (/home/aziz/Desktop/Myprojects/backend/crud_fikri/crud-nodejs-mysql/index.js:22:6)
    at Module._compile (internal/modules/cjs/loader.js:1128:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:983:32)
    at Function.Module._load (internal/modules/cjs/loader.js:891:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {

  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3306,
  fatal: true
}

2 Answers2

0

It seems like the connection to your db was refused. Make sure you are using the correct database account and that it has privileges.

Also make sure to whitelist your app from db.

You need to whitelist the following ips: 127.0.0.1 and localhost

this thread can possibly be of help: node.js mysql error: ECONNREFUSED

Muhand Jumah
  • 1,726
  • 1
  • 11
  • 26
0

Yes, you need a MySQL DB running. The easiest way is to install Docker on your machine, and use the official MySQL container.

Josh Wulf
  • 4,727
  • 2
  • 20
  • 34