[BUG] localhost will be replaced by ::1

8 views
Skip to first unread message

Adrian Preuß

unread,
Mar 28, 2025, 5:32:50 AMMar 28
to node-mysql
**Version:** `"mysql": "^2.18.1"`

Connection is not opened correctly. Instead of the host name `localhost` is automatically replaced by `::1`.

# Code
```javascript
import MySQL from 'mysql';
import Config from '/opt/Configuration/server/config.json' with { type: 'json' };

constructor() {
this.Connection = MySQL.createPool({
connectionLimit: Config.Database.CONNECTIONS,
host: Config.Database.HOSTNAME,
port: Config.Database.PORT,
user: Config.Database.USERNAME,
password: Config.Database.PASSWORD,
database: Config.Database.DATABASE,
charset: Config.Database.CHARSET,
timezone: 'Europe/Berlin',
queryFormat: (query, values) => {
if(!values) {
return query;
}

return query.replace(/\:(\w+)/g, (txt, key) => {
if(values.hasOwnProperty(key)) {
return MySQL.escape(values[key]);
}

return txt;
});
}
});
}
```

# JSON-Config
```json
{
"Database": {
"HOSTNAME": "localhost",
"PORT": 3306,
"CONNECTIONS": 5,
"DATABASE": "chatservers",
"USERNAME": "chatservers",
"PASSWORD": "*****PASSWORD*****",
"PREFIX": "cs_",
"CHARSET": "utf8mb4"
}
}
```

# JSON-Test
```
console.log(Config.Database.HOSTNAME);

Output: localhost
```

# Result
> [!CAUTION]
> [ERROR] Database Error: Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'chatservers'@'::1' to database 'chatservers'
at Sequence._packetToError (/opt/Server/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
    at Handshake.ErrorPacket (/opt/Server/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
    at Protocol._parsePacket (/opt/Server/node_modules/mysql/lib/protocol/Protocol.js:291:23)
    at Parser._parsePacket (/opt/Server/node_modules/mysql/lib/protocol/Parser.js:433:10)
    at Parser.write (/opt/Server/node_modules/mysql/lib/protocol/Parser.js:43:10)
    at Protocol.write (/opt/Server/node_modules/mysql/lib/protocol/Protocol.js:38:16)
    at Socket.<anonymous> (/opt/Server/node_modules/mysql/lib/Connection.js:88:28)
    at Socket.<anonymous> (/opt/Server/node_modules/mysql/lib/Connection.js:526:10)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:559:12)
    --------------------
    at Protocol._enqueue (/opt/Server/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/opt/Server/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at PoolConnection.connect (/opt/Server/node_modules/mysql/lib/Connection.js:116:18)
    at Pool.getConnection (/opt/Server/node_modules/mysql/lib/Pool.js:48:16)
    at file:///opt/Server/Core/Database.class.js:91:20
    at new Promise (<anonymous>)
    at Database.fetch (file:///opt/Server/Core/Database.class.js:90:10)
    at file:///opt/Server/Core/Database.class.js:74:9
    at new Promise (<anonymous>)
    at Database.single (file:///opt/Server/Core/Database.class.js:73:10) {
  code: 'ER_DBACCESS_DENIED_ERROR',
  errno: 1044,
  sqlMessage: "Access denied for user 'chatservers'@'::1' to database 'chatservers'",
  sqlState: '42000',
  fatal: true
}

Adrian Preuß

unread,
Mar 28, 2025, 5:49:37 AMMar 28
to node-mysql
The Problem was on MySQL-Server (MariaDB).

If the Option
```
# Broken reverse DNS slows down connections considerably and name resolve is
# safe to skip if there are no "host by domain name" access grants
skip-name-resolve = ON
```

is enabled, the connection will failed on Handshake.

It is possible to add these to the docs?
Reply all
Reply to author
Forward
0 new messages