节点Js mysql(和mysql2)ECONNRESET [英] Node Js mysql(and mysql2) ECONNRESET

查看:122
本文介绍了节点Js mysql(和mysql2)ECONNRESET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用具有mysqlmysql2 NPM依赖项的Node.Js连接到Internet上的MySQL服务器,以使用查询和其他相关内容.

i am currently trying to connect to a MySQL server on the internet using Node.Js with the mysql or the mysql2 NPM dependencies to use queries and other related stuff.

代码很简单...

//i import my dependency
const mysql = require('mysql2') //either 'mysql' or 'mysql2'

//i create my pool to create connections as needed
var conn = mysql.createPool({
    host: 'some_database_i_have_access_to.mysql.uhserver.com',
    user: 'valid_user',
    password: 'valid_password',
    database: 'some_existing_database'
})

//i try to connect (this is the part where it fails)
conn.getConnection((err,conn) => {
    if (err) throw err //<- the error is thrown here

    //i do query stuff
    conn.query("SELECT * FROM atable",(err,res,firlds) => {
        if(err) throw err
        console.log(JSON.stringify(res))
    })
    //i close the connection
    conn.end()
})

但是我总是会收到这样的错误:

yet i always get an Error like this:

Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:111:27)
    --------------------
    at Protocol._enqueue (C:\Users\Aluno\Desktop\my-project\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Protocol.handshake (C:\Users\Aluno\Desktop\my-project\node_modules\mysql\lib\protocol\Protocol.js:51:23)
    at Connection.connect (C:\Users\Aluno\Desktop\my-project\node_modules\mysql\lib\Connection.js:118:18)
    at Object.<anonymous> (C:\Users\Aluno\Desktop\my-project\private\dtp-mysql.js:13:6)
    at Module._compile (internal/modules/cjs/loader.js:707:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
    at Module.load (internal/modules/cjs/loader.js:605:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
    at Function.Module._load (internal/modules/cjs/loader.js:536:3)
    at Module.require (internal/modules/cjs/loader.js:643:17)

我所知道的错误是,此问题中所述的连接突然断开了一侧( Node js ECONNRESET ),但仅此而已,创建单一连接也无法为我解决此问题.

all i know about the error is that the connection abruptly closes in one of the sides as stated in this question (Node js ECONNRESET), but nothing more, and creating singular connections does not solve this issue for me either.

对此有任何解决办法吗?

any fixes to that?

推荐答案

我知道这是在一段时间前被问到的,但这可能是因为您使用的是:

Hi I know this was asked some time ago, but is it possibly because you're using:

conn.end()

conn.end()

由于您使用的是池化连接,因此我认为您可以使用以下方式释放连接

Since you're using a Pooled connection, I think you can release the connection using

conn.release()

conn.destroy()

这篇关于节点Js mysql(和mysql2)ECONNRESET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆