链接应用程序与数据库

我试图用我的数据库连接我的应用程序使用mysql库。 这是我的代码:

//Require Libraries const mysql = require('mysql'); //Set up MySql connection const connection = mysql.createConnection({ host : "255.255.255.255", //that ain't actually the ip :P port : "3306", user : "root", password : "password :P", database : "db_name" }); connection.connect(); //Connect to the database 

代码给出的错误是:

 events.js:182 throw er; // Unhandled 'error' event ^ Error: connect ECONNREFUSED (MY IP IS IN THIS BIT):3306 at Object.exports._errnoException (util.js:1024:11) at exports._exceptionWithHostPort (util.js:1047:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1150:14) -------------------- at Protocol._enqueue (C:\file\location:145:48) at Protocol.handshake (C:\file\location\Protocol.js:52:23) at Connection.connect (C:\file\location\Connection.js:130:18) at Object.<anonymous> (C:\file\location\index.js:25:12) at Module._compile (module.js:569:30) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:503:32) at tryModuleLoad (module.js:466:12) at Function.Module._load (module.js:458:3) at Function.Module.runMain (module.js:605:10) 

如果你想知道,数据库是肯定运行的,我可以连接到它使用MySQL的工作台。 也只是一个简单的说明,数据库是远程托pipe,以防万一,可能会改变任何东西。

如果允许连接到远程数据库的用户从你的“主机”执行此操作,请检查MySQL工作台 – >服务器 – >用户和权限。 有关更多信息,另请参阅此文档 。