How to resolve error on Node.js backend: Connection ECONNREFUSED: :1:3306?
P粉986860950
P粉986860950 2023-08-28 12:36:30
0
1
654
<p>I rebuilt my hosting server, but after setting up mysql, I get the error from the Node.js backend: </p> <pre class="brush:php;toolbar:false;">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</pre> <p>When trying to register and log in on my frontend, the database password is set to "", the hostname is set to localhost, etc. I have allowed 3306 on my ufw but still get the same error.</p> <p>如果这有帮助,下面是我后端的控制台错误:</p> <pre class="brush:php;toolbar:false;">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</pre> <p>我完全迷失了,因为与我之前的托管服务器设置的唯一区别是 mysql 有一个用户密码,与我的前端的总体区别是服务器的 IP 地址,但我不太确定 NginX 是否有一些东西与它有关。</p>
P粉986860950
P粉986860950

reply all(1)
P粉418854048

3306 is the default MySql port... Is your sql server running?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template