节点JS错误错误:连接ECONNREFUSED 127.0.0.1:3306

最后发布: 2019-01-23 14:38:37


问题

我正在尝试运行此脚本:

var mysql = require('mysql');

var con = mysql.createConnection({
  host: "localhost",
  user: "yourusername",
  password: "yourpassword"
 });

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
});  

我不断收到此错误:

Error: connect ECONNREFUSED 127.0.0.1:3306
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)
    --------------------
    at Protocol._enqueue 
(/home/yassine/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake 
(/home/yassine/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at Connection.connect 
(/home/yassine/node_modules/mysql/lib/Connection.js:118:18)
    at Object.<anonymous> (/home/yassine/demo_db_connection.js:9:5)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)

我正在使用Ubuntu 18.04。 有人可以帮忙吗..

mysql node.js ubuntu