简体   繁体   中英

ER_ACCESS_DENIED_ERROR: Access denied on nodeJS

MySQL is connecting to a different unknown IP when trying to connect. Code Below:

.env

MYSQL_HOST=domain.example.com
MYSQL_USER=****
MYSQL_PASSWORD=****
MYSQL_DB=****
MYSQL_PORT=3306

connection.js

const mysql = require("mysql");

exports.pool = mysql.createPool({
  connectionLimit: 10,
  host: process.env.MYSQL_HOST,
  port: process.env.MYSQL_PORT,
  user: process.env.MYSQL_USER,
  password: process.env.MYSQL_PASSWORD,
  database: process.env.MYSQL_DB,
});

controller/cron

pool.getConnection((err, connection) => {
        if (err) {
          console.log("ERROR: ", err);
        } else { ... insert data .... }
});

With this i'm getting error:

try connecting to remote mysql...
Error:  Error: ER_ACCESS_DENIED_ERROR: Access denied for user '****'@'112.200.198.66' (using password: YES)

Tested in MySQL Workbench and successfully connected. I'm just curious where the IP came from when the public IP of that domain is different. Also tried using the IP instead to connect and still giving me the same error.

If you're using MySQL 8 the issue could be that the Node mysql driver uses a different authentication plugin - see Node.js can't authenticate to MySQL 8.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM