[英]Not able to connect Mysql database from Node.js for forgot password mechanism in Expo App Mac OS
I am building an Expo App in ' MacOS Mojave 10.14.6 ' using mysql database.I want to create forgot password page which needs to send email notification to user to reset password.So I am writing a Node.js program which will connect to 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 连接到数据库。谁能说出我哪里出错了。在此先感谢。
实际上,我在 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;
output如下:
Database is connected!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.