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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠