Error: connect ECONNREFUSED 127.0.0.1:3306

用nodejs调用MySQL,按照http://blog.fens.me/nodejs-mysql-intro/的示例写好(他是写在app.js,我另建了一个文件),一运行报错如下:


Error: connect ECONNREFUSED 127.0.0.1:3306
    at Object.exports._errnoException (util.js:837:11)
    at exports._exceptionWithHostPort (util.js:860:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1060:14)
    --------------------
    at Handshake.Sequence (D:\Android\workspace\SDKAutoTest\node_modules\mysql\lib\protocol\sequences\Sequence.js:15:20)
    at new Handshake (D:\Android\workspace\SDKAutoTest\node_modules\mysql\lib\protocol\sequences\Handshake.js:9:12)
    at Protocol.handshake (D:\Android\workspace\SDKAutoTest\node_modules\mysql\lib\protocol\Protocol.js:42:50)
    at Connection.connect (D:\Android\workspace\SDKAutoTest\node_modules\mysql\lib\Connection.js:72:18)
    at Object. (D:\Android\workspace\SDKAutoTest\src\mysql.js:12:6)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)

搜索错误提示,得到答案http://stackoverflow.com/questions/30266221/node-js-mysql-error-connect-econnrefused,可我搜遍硬盘也没有*.sock

最后还是在w3cShool得到启发,应该先安装MySQL,(⊙﹏⊙)b

安装完修改一下用户名密码和数据库名称,果然OK了(我在Windows平台运行,mysql的installer会自动配置,所以不需要配置*.sock,那应该是Linux下的)

你可能感兴趣的:(Error: connect ECONNREFUSED 127.0.0.1:3306)