我在尝试着通过node.js连接mysql程序,但它抛出一个错误。
我无法连接到端口 3306 上的 mysql。我已经我的电脑上安装了 apache。
我努力了http://www.cyberciti.biz/tips/linux-iptables-18-allow-mysql-server-incoming-request.html
但它仍然不起作用。
错误 :
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
--------------------
at Handshake.Sequence (/opt/lampp/htdocs/1nodeapp/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:20)
at new Handshake (/opt/lampp/htdocs/1nodeapp/node_modules/mysql/lib/protocol/sequences/Handshake.js:9:12)
at Protocol.handshake (/opt/lampp/htdocs/1nodeapp/node_modules/mysql/lib/protocol/Protocol.js:42:50)
at Connection.connect (/opt/lampp/htdocs/1nodeapp/node_modules/mysql/lib/Connection.js:72:18)
at Connection._implyConnect (/opt/lampp/htdocs/1nodeapp/node_modules/mysql/lib/Connection.js:182:10)
at Connection.query (/opt/lampp/htdocs/1nodeapp/node_modules/mysql/lib/Connection.js:97:8)
at Server.<anonymous> (/opt/lampp/htdocs/1nodeapp/mysql.js:22:18)
at Server.EventEmitter.emit (events.js:98:17)
at HTTPParser.parser.onIncoming (http.js:2108:12)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:121:23)
答案1
总结以上内容:
1)尝试使用标准 mysql 客户端进行连接 2)如果可行,找出它使用的端口
netstat -nlp | grep -i mysql
以便您可以配置适当的防火墙端口
3)如果不起作用,运行
ps -ef | grep -i mysql | grep -v grep
检查 mysql 是否实际正在运行 4)如果没有(就像这里的情况一样)启动它,如果连接仍然失败,则重复。