我正在尝试使用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 workbench连接到它。另外,请注意远程托管数据库,以防万一可能发生任何变化。
答案 0 :(得分:0)
如果允许连接到远程数据库的用户从您的&#34;主机&#34;进行操作,请检查MySQL工作台 - &gt; Server-&gt; Users_and_Privileges。有关详细信息,另请参阅this documentation。