0
const mysql = require('mysql');

const dbConn = mysql.createConnection({
  host: 'xx.xxx.xxx.xx',
  database: 'ucha_txxxxxx',
  user: 'ucha_axxxxxx',
  password: 'txxxxxxxxxxxx',
  port: 8090,
});

dbConn.connect(function (err) {
  if (err) {
    console.log("Error in connection request", err);
    return;
  }
  console.log("Connection Successful-----------------------");
});

module.exports = dbConn;

This is my code for Database Connection. Initially I used phpMyAdmin localhost for testing my app, since I have to deploy my application, I have to change my database from localhost to a private server. I added the details of the private server and that is where I am facing the problems. I checked multiple times if I had entered the right details. I even tried using Pool but had the same issue. To check if my database connection has been established, I run

node index.js 

in my terminal. It should display either of the two results written in dbConn.connect(), but I am getting neither. I even tried adding connection Timeout too but couldn't get any results. Please let me know if I am doing anything wrong.

FYI- I am using Webserver enter image description herefor hosting my database

Here is a screenshot of my code snippet.

I tried solutions from multiple websites and YouTube videos, even consulted my senior developer but couldn't get the expected result. I am hoping to get any kind of help from here.

10
  • MySQL normally runs on port 3306! Port 8090 looks like a port number you might use for Apache or the web server if you were changing the web server port Commented Nov 3, 2022 at 15:10
  • So MySQL is not running on 8090 as only one thing can be listening on a port. try changing that to 3306 Commented Nov 3, 2022 at 15:35
  • @RiggsFolly Just tried it, showing an error as "Host '50.200.9.254' is not allowed to connect to this MariaDB server" I do not have any Host as 50.200.9.254 Commented Nov 3, 2022 at 15:39
  • So at least you are not talking to mariaDB because that is a mariaaDB error message. So MySQL (mariaDB) is running on 3306 as suspected Commented Nov 3, 2022 at 15:40
  • You now have to setup that user account in mariaDB, so it is allowed to connect from a remote ip address. Commented Nov 3, 2022 at 15:41

1 Answer 1

1

Port 8090 is running a HTTPs Server on your IP, MySQL/MariaDB runs on Port 3306 (which is also open to anyone - more on that later)

The error you described shows that your user is not allowed with that specific IP (probably your IP address of your (home?-)router).

Usually you create user and permissions like this:

CREATE USER '<username>'@'<ip or host>' IDENTIFIED BY '<password>>';
GRANT ALL PRIVILEGES ON <database>.<table> TO '<username>'@'<ip or host>';

If you want to access it from any host you can use % as < ip or host >

WARNING: You should never ever access MySQL over the internet (which looks to me like you do). Usually you don't even want to expose MariaDB to the internet (bind-address in MySQL/MariaDB configuration)

You also have many other ports open to anyone in the world - please check if all of them need to be exposed. Also you maybe want to mask the IP you used in your question.

If you are developing locally its probably best to install a MariaDB locally on your PC (e.g. via Docker) - if you have to use that specific server you should do it over some sort of Tunnel (VPN, SSH).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.