G
G
gohellp2021-07-02 16:58:10
MySQL
gohellp, 2021-07-02 16:58:10

Why won't mysql let the bot?

I took a VPS, somehow raised one bot on it through a stump-deck, was delighted, and decided to raise the second one. Having transferred the database and the bot itself, I ran into such a problem: I can use it through the console and the client, but on mysql2 in the bot it swears "ACCEST DENIED":

# node main
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: Access denied for user 'root'@'localhost'
    at Packet.asError (/root/bots/dc_gth/node_modules/mysql2/lib/packets/packet.js:712:17)
    at ClientHandshake.execute (/root/bots/dc_gth/node_modules/mysql2/lib/commands/command.js:28:26)
    at Connection.handlePacket (/root/bots/dc_gth/node_modules/mysql2/lib/connection.js:425:32)
    at PacketParser.Connection.packetParser.p [as onPacket] (/root/bots/dc_gth/node_modules/mysql2/lib/connection.js:75:12)
    at PacketParser.executeStart (/root/bots/dc_gth/node_modules/mysql2/lib/packet_parser.js:75:16)
    at Socket.Connection.stream.on.data (/root/bots/dc_gth/node_modules/mysql2/lib/connection.js:82:25)
    at Socket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at Socket.Readable.push (_stream_readable.js:224:10)
Emitted 'error' event at:
    at Connection._notifyError (/root/bots/dc_gth/node_modules/mysql2/lib/connection.js:225:12)
    at ClientHandshake.Connection.handshakeCommand.on.err (/root/bots/dc_gth/node_modules/mysql2/lib/connection.js:114:14)
    at ClientHandshake.emit (events.js:203:15)
    at ClientHandshake.execute (/root/bots/dc_gth/node_modules/mysql2/lib/commands/command.js:33:14)
    at Connection.handlePacket (/root/bots/dc_gth/node_modules/mysql2/lib/connection.js:425:32)
    [... lines matching original stack trace ...]
    at addChunk (_stream_readable.js:288:12)

when using mysql-client itself:
# mysql -p -u root
Enter password: %mypass%
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 8.0.25-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

For the second day I've been googling, I'm struggling and googling - it doesn't help. The password, address and username (root, who would be wrong here?: D) are definitely correct.
If, nevertheless, I screwed up (which I'm not sure about, since under Windows the same database works fine with the code):
const mysql = require('mysql2');
const cfg = require('./config.json');

const connection = mysql.createConnection({
  host:"localhost",
  user:cfg.dbLogin,
  database:"gth_db",
  password:cfg.dbPass
});

If I'm stupid somewhere, please explain, since I'm with mysql "on you", and with it, only on the link at all "on the highly respected".
Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
gohellp, 2021-07-03
@gohellp

Fixed by creating a new user and giving him almost all rights.
The only thing is that mysql swears at any operations, although the user has the rights to them ...
1) Create a user:
CREATE USER 'user'@'%' IDENTIFIED BY 'password';
2) Grant rights (for each necessary database separately):

GRANT ALL PRIVILEGES ON database.table TO 'user'@'%';

This helped me ... What RUTA lacked in terms of rights - one can only guess ... Moreover, local access is toooo ...

S
Satisfied IT, 2021-07-02
specialist @borisdenis

Error: Access denied for user 'root'@'localhost'

Most likely, the bot was given the wrong password (config.json). What's in the mysql logs? Are there any records that the root user is trying to connect with the wrong password?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question