I'm facing trouble to do local development of an express app to access my WordPress database (which is on https://example.com). Here's my configuration (which work because I could make it work with a local database. I already tried without the 3306) :
module.exports = {
HOST: "https://example.com:3306",
USER: "user",
PASSWORD: "password",
DB: "mydb"
};
const mysql = require("mysql2");
const dbConfig = require("../config/db.config.js");
// Create a connection to the database
const connection = mysql.createConnection({
host: dbConfig.HOST,
user: dbConfig.USER,
password: dbConfig.PASSWORD,
database: dbConfig.DB
});
// open the MySQL connection
connection.connect(error => {
if (error) throw error;
console.log("Successfully connected to the database.");
});
module.exports = connection;
I'm using webmin/virtualmin to manage my different VPS. Here's what I've done :
Even like that, I can't make the connection. Anyone know why? The error I get is this:
Error: getaddrinfo ENOTFOUND https://example.com:3306
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:69:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'https://example.com:3306',
fatal: true
}
I fixed my problem. The "error not found" was because I put the host as "example.com" instead of "190.x.x.x" (the ip address).
Then, I got a "timed out" error. What I did below was useless. You have to authorize MySQL to listen to other ports, then authorize the databse herself to do so, and finally configure the firewall. Here are the steps: