Bagaimana untuk menyelesaikan ralat pada bahagian belakang Node.js: Sambungan ECONNREFUSED: :1:3306?
P粉986860950
2023-08-28 12:36:30
<p>Saya membina semula pelayan pengehosan saya, tetapi selepas menyediakan mysql, saya mendapat ralat daripada bahagian belakang Node.js: </p>
<pre class="brush:php;toolbar:false;">Ralat: sambung ECONNREFUSED ::1:3306
di TCPConnectWrap.afterConnect [sebagai oncomplete] (nod:net:1494:16)
-------------------
di Protocol._enqueue (/home/smartcrop/smartcrop/node_modules/mysql/lib/protocol/Protocol.js:144:48)
di Protocol.handshake (/home/smartcrop/smartcrop/node_modules/mysql/lib/protocol/Protocol.js:51:23)
di Connection.connect (/home/smartcrop/smartcrop/node_modules/mysql/lib/Connection.js:116:18)
di Connection._implyConnect (/home/smartcrop/smartcrop/node_modules/mysql/lib/Connection.js:454:10)
di Connection.query (/home/smartcrop/smartcrop/node_modules/mysql/lib/Connection.js:196:8)
di file:///home/smartcrop/smartcrop/server/index.js:165:10 {
errno: -111,
kod: 'ECONNREFUSED',
syscall: 'sambung',
alamat 1',
pelabuhan: 3306,
maut: benar
}
file:///home/smartcrop/smartcrop/server/index.js:196
jika (hasil.panjang > 0) {
^
TypeError: Tidak dapat membaca sifat yang tidak ditentukan (membaca 'panjang')
di Query.<tanpa nama> (fail:///home/smartcrop/smartcrop/server/index.js:196:20)
di Query.<tanpa nama> (/home/smartcrop/smartcrop/node_modules/mysql/lib/Connection.js:526:10)
di Query._callback (/home/smartcrop/smartcrop/node_modules/mysql/lib/Connection.js:488:16)
di Sequence.end (/home/smartcrop/smartcrop/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24)
di /home/smartcrop/smartcrop/node_modules/mysql/lib/protocol/Protocol.js:236:14
di process.processTicksAndRejections (node:internal/process/task_queues:77:11)
Node.js v18.15.0</pre>
<p>Apabila cuba mendaftar dan log masuk pada bahagian hadapan saya, kata laluan pangkalan data ditetapkan kepada "", nama hos ditetapkan kepada localhost, dsb. Saya telah membenarkan 3306 pada ufw saya tetapi masih mendapat ralat yang sama.</p>
<p>如果这有帮助,下面是我后端的控制台错误:</p>
<pre class="brush:php;toolbar:false;">cess to XMLHttpRequest di 'http://157.245.193.191/register' dari asal 'http://localhost:3000' telah disekat oleh dasar CORS: Tiada pengepala 'Access-Control-Allow-Origin' hadir pada sumber yang diminta.
xhr.js:217
POST http://157.245.193.191/register net::ERR_FAILED 502 (Gerbang Buruk)
dispatchXhrRequest @ xhr.js:217
xhr @ xhr.js:41
dispatchRequest @ dispatchRequest.js:43
permintaan @ Axios.js:123
httpKaedah @ Axios.js:159
bungkus @ bind.js:5
daftar @ 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
(tanpa nama) @ 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 Tidak ditangkap (dalam janji) AxiosError {mesej: 'Ralat Rangkaian', nama: 'AxiosError', kod: 'ERR_NETWORK', konfigurasi: {…}, permintaan: XMLHttpRequest, …}
P</pra>
<p>我完全迷失了,因为与我之前的托管服务器设置的唯一区别是与我之前的托管服务器设置的唯一区别是与我之前的托管服务器设置的唯一区别是 mysql 有用一一的总体区别是服务器的 IP 地址,但我不太确定 NginX 是否有一些东西与它有关。</p>
3306 ialah port MySql lalai... Adakah pelayan sql anda berjalan?