V
V
Vladimir2019-11-18 00:39:13
MySQL
Vladimir, 2019-11-18 00:39:13

Why does mysql write access_denied_error after installation on hosting, installed everything according to the documentation?

Good night. I'm trying to start on the host, documentation
Project on node.js, everything is ok, everything starts, except mysql, I connect via socketPath, googled the problem, they advised me to put socketPath in the port, it didn't work ..
I threw a ticket in those. support, I’m waiting, maybe one of you guys has come across, I’ll be most grateful for the help, because. worth development
Here is my class, I take data from dotenv

const { mysql,dotenv,initializeDotenv,util } = require('./packages')

class Mysql {

  constructor(host,user,password,database,socket) {

    this.connection
    this.host = host
    this.user = user
    this.password = password
    this.database = database
    this.socket = socket

    if(socket) {
      this.connection = mysql.createPool({
           socketPath: this.socket,
           port: 3306,
           user: this.user,
           password: this.password,
           database: this.database
      })
    }

    else {
      this.connection = mysql.createPool({
           host: this.host,
           port: 3306,
           user: this.user,
           password: this.password,
           database: this.database
      });
    }

    return this.connection
  }

}

const { HOST,USER,PASSWORD,DATABASE,SOCKET } = process.env;

const pool = new Mysql(HOST,USER,PASSWORD,DATABASE,SOCKET)

pool.getConnection((err, connection) => {
  if (err) {
    console.error(err.code)
  }
  if (connection) connection.release()
})

pool.query = util.promisify(pool.query)

module.exports = { Mysql,pool }

.env
#Project mode
NODE_ENV=production

#App port
PORT=51583

#Mysql

HOST=localhost

USER=user

PASSWORD=password

DATABASE=db

SOCKET=/var/run/mysqld/mysqld.sock

#Bcrypt

COMPLEXITY=10

#Secret for sessions

SECRET=$$999$$

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Karasik, 2019-11-18
@vitaly_il1

does mysql -u user -p password -s /var/run/mysqld/mysqld.sock
work?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question