为什么在我的 namecheap nodejs 应用程序中访问被拒绝?

Why am I getting Access denied in my namecheap nodejs app?

我使用 NodeJS、Express 和 MariaDB 创建了一个简单的 API 来测试我遇到的数据库连接问题。这在本地工作正常,但在 NameCheap 服务器上却不行。 这是我得到的错误:

(conn=18541114, no: 1045, SQLState: 28000) Access denied for user 'madejnsw_demouser'@'localhost' (using password: YES)

错误日志:

    at Object.module.exports.createError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/misc/errors.js:61:10)
    at Handshake.throwError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/command.js:82:22)
    at Handshake.handshakeResult (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/handshake/handshake.js:131:28)
    at PacketInputStream.receivePacketBasic (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
 From event:
    at _registerHandshakeCmd (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:745:11)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:373:9)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:392:7
    at new Promise (<anonymous>)
    at connectionCreationLoop (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:356:12)
    at PoolPromise.PoolBase.initialize (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:142:5)
(node:2798261) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:2798261) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2806739) UnhandledPromiseRejectionWarning: Error: (conn=17370601, no: 1045, SQLState: 28000) Access denied for user 'madejnsw_demouser'@'localhost' (using password: YES)
    at Object.module.exports.createError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/misc/errors.js:61:10)
    at Handshake.throwError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/command.js:82:22)
    at Handshake.handshakeResult (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/handshake/handshake.js:131:28)
    at PacketInputStream.receivePacketBasic (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
 From event:
    at _registerHandshakeCmd (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:745:11)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:373:9)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:392:7
    at new Promise (<anonymous>)
    at connectionCreationLoop (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:356:12)
    at PoolPromise.PoolBase.initialize (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:142:5)
(node:2806739) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:2806739) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2807107) UnhandledPromiseRejectionWarning: Error: (conn=17370830, no: 1045, SQLState: 28000) Access denied for user 'madejnsw_demouser'@'localhost' (using password: YES)
    at Object.module.exports.createError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/misc/errors.js:61:10)
    at Handshake.throwError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/command.js:82:22)
    at Handshake.handshakeResult (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/handshake/handshake.js:131:28)
    at PacketInputStream.receivePacketBasic (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
 From event:
    at _registerHandshakeCmd (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:745:11)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:373:9)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:392:7
    at new Promise (<anonymous>)
    at connectionCreationLoop (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:356:12)
    at PoolPromise.PoolBase.initialize (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:142:5)
(node:2807107) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:2807107) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2813149) UnhandledPromiseRejectionWarning: Error: (conn=17375021, no: 1045, SQLState: 28000) Access denied for user 'madejnsw_demouser'@'localhost' (using password: YES)
    at Object.module.exports.createError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/misc/errors.js:61:10)
    at Handshake.throwError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/command.js:82:22)
    at Handshake.handshakeResult (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/handshake/handshake.js:131:28)
    at PacketInputStream.receivePacketBasic (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
 From event:
    at _registerHandshakeCmd (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:745:11)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:373:9)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:392:7
    at new Promise (<anonymous>)
    at connectionCreationLoop (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:356:12)
    at PoolPromise.PoolBase.initialize (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:142:5)
(node:2813149) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:2813149) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2817491) UnhandledPromiseRejectionWarning: Error: (conn=17377684, no: 1045, SQLState: 28000) Access denied for user 'madejnsw_demouser'@'localhost' (using password: YES)
    at Object.module.exports.createError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/misc/errors.js:61:10)
    at Handshake.throwError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/command.js:82:22)
    at Handshake.handshakeResult (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/handshake/handshake.js:131:28)
    at PacketInputStream.receivePacketBasic (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
 From event:
    at _registerHandshakeCmd (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:745:11)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:373:9)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:392:7
    at new Promise (<anonymous>)
    at connectionCreationLoop (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:356:12)
    at PoolPromise.PoolBase.initialize (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:142:5)
(node:2817491) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:2817491) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:3226965) UnhandledPromiseRejectionWarning: Error: (conn=17531002, no: 1045, SQLState: 28000) Access denied for user 'madejnsw_demouser'@'localhost' (using password: YES)
    at Object.module.exports.createError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/misc/errors.js:61:10)
    at Handshake.throwError (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/command.js:82:22)
    at Handshake.handshakeResult (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/cmd/handshake/handshake.js:131:28)
    at PacketInputStream.receivePacketBasic (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:104:9)
    at PacketInputStream.onData (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/io/packet-input-stream.js:169:20)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
 From event:
    at _registerHandshakeCmd (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:745:11)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:57:11
    at new Promise (<anonymous>)
    at Connection.connect (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/connection.js:56:16)
    at createConnectionPoolPromise (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-promise.js:31:8)
    at creationTryout (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:373:9)
    at /home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:392:7
    at new Promise (<anonymous>)
    at connectionCreationLoop (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:356:12)
    at PoolPromise.PoolBase.initialize (/home/madejnsw/nodevenv/SimpleAPI/12/lib/node_modules/mariadb/lib/pool-base.js:142:5)
(node:3226965) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:3226965) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

这是我的简单server.js:

const express = require('express');
const dotenv = require('dotenv');

dotenv.config({path: '.env-local'});

const PORT = process.env.PORT || '3000';
const app = express();

const userRouter = require('./routes/user');


app.use(express.json());
app.use(express.urlencoded({extended:false}));

//routes
app.get('/', (req, res) => {
    res.status(200).send("this is not why you're here. Go to /user/:id and replace :id with your user id.");
});

//middleware
app.use('/user', userRouter);

//start listening
/*
app.listen(PORT, () => {
    console.log(`Listening on port ${PORT}`);
});
*/
app.listen();

user.js

const express = require('express');
const router = express.Router();
const pool = require('../helpers/database');
const bcrypt = require('bcrypt');

router.get('/:id', async (req, res) => {
    try {
        const sqlQuery = 'SELECT id, email, password, created_at FROM user WHERE id=?';
        const rows = await pool.query(sqlQuery, req.params.id);
        res.status(200).json(rows);
    } catch (error) {
        res.status(400).send(error.message);
    }
    //res.status(200).json({id:req.params.id});
})

router.post('/register', async (req,res) => {
    try {
        const {email, password} = req.body;

        const encryptedPassword = await bcrypt.hash(password, 10);

        const sqlQuery = 'INSERT INTO user (email, password) VALUES (?,?)';
        const result = await pool.query(sqlQuery, [email, encryptedPassword]);

        res.status(200).json({userId: result.insertId});
    } catch (error) {
        res.status(400).send(error.message);
    }
});

module.exports = router;

database.js:

const mariadb = require('mariadb');

const pool = mariadb.createPool({
    host: process.env.DB_HOST,
    user: process.env.DB_USER,
    password: process.env.DB_PASS,
    database: process.env.DB_NAME,
    connectionLimit: 5
})

//connect/check for errors
pool.getConnection((err, connection) => {
    if(err) {
        if (err.code === 'PROTOCOL_CONNECTION_LOST') {
            console.error('Database connection lost');
        }
        if (err.code === 'ER_CON_COUNT_ERROR') {
            console.error('Database has too many connection');
        }
        if (err.code === 'ECONNREFUSED') {
            console.error('Database connection was refused');
        }
    }
    console.log('yes connected!!: ', connection);
    if (connection) connection.release();

    return;
});

module.exports = pool;

我也设置了 Namecheap 环境变量:

#PORT=3000
DB_HOST= localhost
DB_USER= madejnsw_demouser
DB_PASS= A(uGZY$Psx81
DB_NAME= madejnsw_demo_user

用户也拥有所有权限,我无法解决 Namecheap 的这个问题,有人成功地在 namecheap 服务器上启动了一个带有 mariadb 数据库的工作 nodejs 应用程序吗?我将不胜感激这里的任何帮助。 谢谢。

我使用 Namecheap PhpMyAdmin 重新创建了数据库,并且支持人员必须最终修复一些终端问题。