【问题标题】:Not able to connect Mysql database from Node.js for forgot password mechanism in Expo App Mac OS无法从 Node.js 连接 Mysql 数据库以在 Expo App Mac OS 中忘记密码机制
【发布时间】:2022-01-12 06:08:33
【问题描述】:

我正在使用 mysql 数据库在“MacOS Mojave 10.14.6”中构建一个 Expo 应用程序。我想创建忘记密码页面,该页面需要向用户发送电子邮件通知以重置密码。所以我正在编写一个 Node.js 程序将连接到 Mysql。但我收到错误。

下面是 Node.js 数据库程序:

数据库.js:

var mysql=require('mysql2');
var connection=mysql.createConnection({
host:'localhost',
user:'root',
password:'',
database:'*******'
});

connection.connect((err) => {

if(!err)
    console.log('Database is connected!');
else
    console.log('Database not connected! : '+ JSON.stringify(err, undefined,2));
});
module.exports = connection;

运行上述程序后,我收到以下错误:

Database not connected! : {
"code": "ER_ACCESS_DENIED_ERROR",
"errno": 1045,
"sqlState": "28000",
"sqlMessage": "Access denied for user 'root'@'localhost' (using password: NO)"
}

我尝试使用以下命令更改 Mysql Workbench 中的密码:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Test123'; 但它给出了一个错误:

ALTER 和 SYSTEM USER 用法不正确。

我可以使用用户名和密码从 Mysql Workbench 连接到数据库。谁能告​​诉我哪里出错了。在此先感谢。

【问题讨论】:

  • 你检查过this吗?

标签: mysql node.js macos expo mysql-workbench


【解决方案1】:

实际上,我在 Google Cloud Platform 中有我的 mysql 数据库,具有单独的主机名、用户名和密码。我可以通过提供正确的凭据连接到该数据库。

下面是database.js代码:

var mysql=require('mysql2');
var connection=mysql.createConnection({
host:'78.89.***.**',
user:'Poornima',
password:'test123',
database:'testdb'
});

connection.connect((err) => {

if(!err)
console.log('Database is connected!');
else
console.log('Database not connected! : '+ JSON.stringify(err, 
undefined,2));
});
module.exports = connection;

输出如下:

Database is connected!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    • 2014-11-25
    • 1970-01-01
    • 2013-07-20
    • 2012-01-31
    • 2019-09-23
    • 2013-03-06
    相关资源
    最近更新 更多