0

I'm having a problem connecting to a database through the mysql2 module for Node.js.

Everything worked, before I deleted some file to do with 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

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

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.

btwon
  • 46
  • 8
  • 1
    Maybe the MySQL server on your machine is not running? Or maybe it is listening only on `127.0.0.1` and not `::1`? Or maybe you intend to connect to some remote database but accidentally deleted your DB connection configuration and you are now defaulting to localhost? – CherryDT Sep 14 '22 at 17:26

1 Answers1

0

mysql> select @@hostname

For some reason this was set to 'r.local', and upon entering that in the connection object it seems to work. Although now it takes a couple of seconds to load, which is a problem.

btwon
  • 46
  • 8
  • What did you do ? I don't understand – Leccho Dec 14 '22 at 23:05
  • @Leccho after logging into MySQL as root, I entered `SELECT @@hostname` which gave me the correct value to use in the connection object. Since then I've set it back to 'localhost', and it's working fine. Unfortunately I can't remember exactly what I did but if it's any help, these are the options I use in my connection objects: charset = 'utf8mb4', host = 'localhost', database = '...', socketPath = '/tmp/mysql.sock', port = 3306 running on MacOS – btwon Dec 16 '22 at 07:50