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...

asked 4 years ago918 views
2 Answers
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.

answered 4 years ago
0

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

Regards,
Jim Crowell

answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions