如何解决 Node.js 后端上的错误:连接 ECONNREFUSED : :1:3306?
P粉986860950
P粉986860950 2023-08-28 12:36:30
[MySQL讨论组]

我重建了我的托管服务器,但在设置 mysql 后,我从 Node.js 后端收到错误:

Error: connect ECONNREFUSED ::1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16)
    --------------------
    at Protocol._enqueue (/home/smartcrop/smartcrop/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/home/smartcrop/smartcrop/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at Connection.connect (/home/smartcrop/smartcrop/node_modules/mysql/lib/Connection.js:116:18)
    at Connection._implyConnect (/home/smartcrop/smartcrop/node_modules/mysql/lib/Connection.js:454:10)
    at Connection.query (/home/smartcrop/smartcrop/node_modules/mysql/lib/Connection.js:196:8)
    at file:///home/smartcrop/smartcrop/server/index.js:165:10 {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 3306,
  fatal: true
}
file:///home/smartcrop/smartcrop/server/index.js:196
        if (result.length > 0) {
                   ^

TypeError: Cannot read properties of undefined (reading 'length')
    at Query.<anonymous> (file:///home/smartcrop/smartcrop/server/index.js:196:20)
    at Query.<anonymous> (/home/smartcrop/smartcrop/node_modules/mysql/lib/Connection.js:526:10)
    at Query._callback (/home/smartcrop/smartcrop/node_modules/mysql/lib/Connection.js:488:16)
    at Sequence.end (/home/smartcrop/smartcrop/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
    at /home/smartcrop/smartcrop/node_modules/mysql/lib/protocol/Protocol.js:236:14
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

Node.js v18.15.0

当尝试在我的前端注册和登录时,数据库密码设置为“”,主机名设置为 localhost 等,我已经在我的 ufw 上允许 3306,但仍然遇到相同的错误。

如果这有帮助,下面是我后端的控制台错误:

cess to XMLHttpRequest at 'http://157.245.193.191/register' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

xhr.js:217     
POST http://157.245.193.191/register net::ERR_FAILED 502 (Bad Gateway)

dispatchXhrRequest @ xhr.js:217
xhr @ xhr.js:41
dispatchRequest @ dispatchRequest.js:43
request @ Axios.js:123
httpMethod @ Axios.js:159
wrap @ bind.js:5
register @ Signup.js:55
callCallback @ react-dom.development.js:3733
invokeGuardedCallbackDev @ react-dom.development.js:3777
invokeGuardedCallback @ react-dom.development.js:3834
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:3848
executeDispatch @ react-dom.development.js:7992
processDispatchQueueItemsInOrder @ react-dom.development.js:8018
processDispatchQueue @ react-dom.development.js:8029
dispatchEventsForPlugins @ react-dom.development.js:8038
(anonymous) @ react-dom.development.js:8198
batchedUpdates$1 @ react-dom.development.js:22595
batchedUpdates @ react-dom.development.js:3581
dispatchEventForPluginEventSystem @ react-dom.development.js:8197
dispatchEventWithEnableCapturePhaseSelectiveHydrationWithoutDiscreteEventReplay @ react-dom.development.js:5703
dispatchEvent @ react-dom.development.js:5697
dispatchDiscreteEvent @ react-dom.development.js:5674
xhr.js:135 Uncaught (in promise) AxiosError {message: 'Network Error', name: 'AxiosError', code: 'ERR_NETWORK', config: {…}, request: XMLHttpRequest, …}
P

我完全迷失了,因为与我之前的托管服务器设置的唯一区别是 mysql 有一个用户密码,与我的前端的总体区别是服务器的 IP 地址,但我不太确定 NginX 是否有一些东西与它有关。

P粉986860950
P粉986860950

全部回复(1)
P粉418854048

3306 是默认的 MySql 端口...您的 sql 服务器正在运行吗?

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号