简体   繁体   中英

i am receiving error while making connection of mysql database(phpmyadmin) to node.js

{ 
Error: connect ECONNREFUSED 127.0.0.1:3306
    at Object.exports._errnoException (util.js:1020:11)
    at exports._exceptionWithHostPort (util.js:1043:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
    --------------------
    at Protocol._enqueue (/home/ubuntu/workspace/proj/node_modules/mysql/lib/protocol/Protocol.js:145:48)
    at Protocol.handshake (/home/ubuntu/workspace/proj/node_modules/mysql/lib/protocol/Protocol.js:52:23)
    at Connection.connect (/home/ubuntu/workspace/proj/node_modules/mysql/lib/Connection.js:130:18)
    at Object.<anonymous> (/home/ubuntu/workspace/proj/app.js:12:4)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Timeout.Module.runMain [as _onTimeout] (module.js:604:10)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3306,
  fatal: true }

IDE Screenshot

Seems like your database is not running on port 3306.

Try and find out the port number and add the port attribute so your code is like this:

var db = mysql.createConnection({
    host: "127.0.0.1",
    user: "root",
    password: "",
    database: "udit1",
    port: YOUR_PORT_NUMBER_HERE
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM