首页 > 解决方案 > 使用环境变量时访问被拒绝错误

问题描述

我是第一次使用 SQL。我正在使用 docker 容器来运行我的 SQL 在我的 node.js 应用程序中,我运行了 followig

let con = mysql.createConnection({
    host: "localhost",
    user: "user",
    password: "password"
})
  
con.connect(function(err) {
    if (err) throw err;
    console.log("Connected!");
})

它连接起来了。但是当我使用环境变量时我得到一个错误

let con = mysql.createConnection({
    host: "localhost",
    user: process.env.USERNAME,
    password: process.env.PASSWORD
})
  
con.connect(function(err) {
    if (err) throw err;
    console.log("Connected!");
})

我收到以下错误。

code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlMessage: "Access denied for user 'vidhyanand'@'172.17.0.1' (using password: YES)",
sqlState: '28000',
fatal: true

标签: sqlnode.jsenvironment-variables

解决方案


推荐阅读