Answer the question
In order to leave comments, you need to log in
ERROR_ACCESS_DENIED_ERROR mysql why does an error occur with valid data?
Good afternoon. I can't connect to the database. I'm working with the database through the code below.
mysql.js
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 }
#Project mode
NODE_ENV=production
#App port
PORT=3000
#Mysql
HOST=localhost
USER=root
PASSWORD=
DATABASE=test
SOCKET=
#Bcrypt
COMPLAXITY=10
#Secret for sessions
SECRET=$$999$$
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question