0
我試圖在Ubuntu虛擬機上啓動我的Node.JS應用程序。該應用程序使用MySQL。當我運行該應用程序時,出現以下有關我認爲是MySQL的錯誤。Ubuntu 16.04 Node.JS應用程序無法連接到MySQL數據庫 - 錯誤:連接ECONNREFUSED
events.js:182
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED myIP:3306
at Object._errnoException (util.js:1041:11)
at _exceptionWithHostPort (util.js:1064:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1153:14)
--------------------
at Protocol._enqueue (/root/pub code test/node_modules/mysql/lib/protocol/Protocol.js:145:48)
at Protocol.handshake (/root/pub code test/node_modules/mysql/lib/protocol/Protocol.js:52:23)
at Connection.connect (/root/pub code test/node_modules/mysql/lib/Connection.js:130:18)
at Object.<anonymous> (/root/pub code test/runTest.js:17:12)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Function.Module.runMain (module.js:609:10)
這是我用來連接到MySQL代碼:
var connection = mysql.createConnection ({
host: "myIP",
user: "root",
password: "password",
database: "dbname"
});
connection.connect()
我已經更換了密碼,數據庫,和主機名出於安全目的,但我確實是雙與檢查所有的人,一起用戶名
Node.JS version: 8.4.0
NPM version: 5.3.0
MySQL version: 5.4.2
Ubuntu: 16.04
我不確定我做錯了什麼來得到這個錯誤,但如果有人知道爲什麼,請讓我知道。非常感謝!