简体   繁体   English

Node.js mysql2模块无法连接

[英]Node.js mysql2 module can't connect

I'm having a problem connecting to a database through the mysql2 module for Node.js.我在通过 Node.js 的 mysql2 模块连接到数据库时遇到问题。

Everything worked, before I deleted some file to do with Git.一切正常,在我删除一些与 Git 相关的文件之前。 After reinstalling everything trying to fix it... still doesn't work.重新安装所有试图修复它的东西后......仍然无法正常工作。

Node outputs:节点输出:

Error: connect ECONNREFUSED::1:3306 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) Emitted 'error' event on Connection instance at: at Connection._notifyError错误:在 TCPConnectWrap.afterConnect [as oncomplete] 处连接 ECONNREFUSED::1:3306 (node:net:1300:16) 在 Connection 实例上发出“错误”事件:在 Connection._notifyError

at Socket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {

errno: -61, code: 'ECONNREFUSED', syscall: 'connect', address: '::1', port: 3306, fatal: true errno:-61,代码:'ECONNREFUSED',系统调用:'connect',地址:'::1',端口:3306,致命:true

edit: In my connection I specify localhost as the host, and I can connect to the database in the terminal using the same user as my connection object.编辑:在我的连接中,我指定 localhost 作为主机,我可以使用与我的连接 object 相同的用户连接到终端中的数据库。

mysql> select @@hostname mysql> select @@主机名

For some reason this was set to 'r.local', and upon entering that in the connection object it seems to work.由于某种原因,它被设置为“r.local”,并且在连接 object 中输入它后,它似乎可以工作。 Although now it takes a couple of seconds to load, which is a problem.虽然现在加载需要几秒钟,但这是一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM