连接时发生:Error ECONNREFUSED
来源:6-5 nodejs 链接 mysql 做成工具
Neolu4ever
2019-07-03
已排查端口为3306
寻找解决方法的过程中,有如下说法:
在配置里加上 socketPath: '/var/run/mysqld/mysqld.sock’
https://stackoverflow.com/questions/30266221/node-js-mysql-error-connect-econnrefused
但是官方的文档里说:在有host和port的情况下,socketPath会被忽略。。。
请老师和各位同学指点迷津!
具体的错误信息如下:
{ Error: connect ECONNREFUSED 127.0.0.1:3306
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
--------------------
at Protocol._enqueue (/Users/jiexinglu/Desktop/Node Blog Server/mysql-test/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/Users/jiexinglu/Desktop/Node Blog Server/mysql-test/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/Users/jiexinglu/Desktop/Node Blog Server/mysql-test/node_modules/mysql/lib/Connection.js:119:18)
at Object. (/Users/jiexinglu/Desktop/Node Blog Server/mysql-test/index.js:13: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)
code: ‘ECONNREFUSED’,
errno: ‘ECONNREFUSED’,
syscall: ‘connect’,
address: ‘127.0.0.1’,
port: 3306,
fatal: true }
3回答
-
Neolu4ever
提问者
2019-07-23
解决的思路是:进入数据库直接调用指令S HOW GLOBAL VARIABLES LIKE 'PORT'
查看链接状态,如果不是3306,则可以去设置文档,应该是my.cnf 里直接手动更改为自己需要的端口。我这边是直接重装了MySQL,变回默认然后就解决了。
00 -
ofeliaLee
2019-07-23
解决啦
012019-07-23 -
双越
2019-07-05
用 workbench 连接没问题?
012019-07-23
相似问题