How to connect MySQL database in nodeJS file.

0

Hi,
I have an AWS Lightsail account designed to service a MySQL database given HTTP "QueryData" parameters. I have it mostly working but I am having difficulty connecting my MySQL database via my node JavaScript code. In the AWS documentation I find all kinds of info on how to connect my MySQL to a MySQL client [e.g. MySQL Workplace] but nothing on how to not use a client and make the connection in my JavaScript code.

Presently I am doing the following :
// Connect to MySQL AWS Lishtsail 'MySQL' database...
const vpsDB = mysql.createConnection(
{ host : 'ls ...us-east-1.rds.amazonaws.com', [i.e. my MySQL Endpoint]
port : '3306',
user : 'dbmasteruser',
password : 'My custom password',
database : 'jFormTK-MySQL'
} );

vpsDB.connect(function(err) {
if(!err) {
console.log("Database is connected ...");
} else {
console.log("Error connecting database ..."lib.nl
err);
}
});

The above yields the following 'err' :
Error connecting database ...
Error: ER_BAD_DB_ERROR: Unknown database 'jFormTK-MySQL'

Can you please point me to where this is documented OR suggest where I have gone wrong.

Using Google I found minimal hits that did not help.
That effort made me think my problem was the 'Host' ordered pair where some shown code used an IP address. I tried using MySQL static IP address but got an error from the 'node' command.

Another suggestion made me think my Security Setting was the culprit but I think LightSail manages that setting for me and have no idea how to control that???

Sorry for the long query but I'm stumped as to what to try next.

Regards,
Jim...

質問済み 4年前894ビュー
2回答
0

Hey Jim,

I'm using the npm mysql-node (https://github.com/mysqljs/mysql) to connect on RDS instance, but I'm not informing my database, because they are separated in Schemas.

// My MySQL Config Object
{
host: '<URL to my RDS instance without protocol http or https>',
port: port,
user: user,
password: 'passowrd'
}

Another thing is to try to confirm the database name, the lower and upper cases maybe.

回答済み 4年前
0

I am now using LightSail and am successfully using MySQL in my VPS instance.

Regards,
Jim Crowell

回答済み 4年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ