Error: connect ECONNREFUSED 127.0.0.1:3306 ( DB not connecting in node js with mysql)

Viewed 4052

I was building a simple rest API with node and mysql. But while creating the connection to the database I am getting this error.

Error: connect ECONNREFUSED 127.0.0.1:3306 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) -------------------- at Protocol._enqueue (/Users/shehriyarnadeem/Documents/others/learning_projects/linkedinclone/node_modules/mysql/lib/protocol/Protocol.js:144:48) at Protocol.handshake (/Users/shehriyarnadeem/Documents/others/learning_projects/linkedinclone/node_modules/mysql/lib/protocol/Protocol.js:51:23) at Connection.connect (/Users/shehriyarnadeem/Documents/others/learning_projects/linkedinclone/node_modules/mysql/lib/Connection.js:116:18) at Object. (/Users/shehriyarnadeem/Documents/others/learning_projects/linkedinclone/config/database.js:12:6) at Module._compile (internal/modules/cjs/loader.js:1138:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10) at Module.load (internal/modules/cjs/loader.js:986:32) at Function.Module._load (internal/modules/cjs/loader.js:879:14) at Module.require (internal/modules/cjs/loader.js:1026:19) at require (internal/modules/cjs/helpers.js:72:18) { errno: 'ECONNREFUSED', code: 'ECONNREFUSED', syscall: 'connect',
address: '127.0.0.1', port: 3306, fatal: true }

database.js

var mysql = require("mysql");

let pool = mysql.createConnection({ host: "localhost", user: "root", port: "3306" /* port on which phpmyadmin run */, password: "",

database: "dbname", });

pool.connect((err) => { console.log(err); });

module.exports = pool;

0 Answers
Related