Jump to content

Node connection to mysql database


Adamhumbug

Recommended Posts

Hi all,

I hope this is the right place to post this.

I am trying to learn node.js and i am really struggling to get going.

I have a mysql database hosted with ionos and i am trying to just start with a connection.

I have the following which is the connection file and i am running it from the command line.

var mysql = require('mysql');

var con = mysql.createConnection({
  host: "xxxxxxx.hosting-data.io",
  user: "xxxxx",
  password: "xxxxx"
});

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
});

I am getting the error:

❯ node db_conn.js
/Users/xxxxxxx/Documents/xxxx/Sites/Node/first/db_conn.js:11
  if (err) throw err;
           ^

Error: getaddrinfo ENOTFOUND xxxxxx.hosting-data.io
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:118:26)
    --------------------
    at Protocol._enqueue (/Users/xxxx/Documents/xxxx/Sites/Node/first/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/Users/xxxx/Documents/xxxx/Sites/Node/first/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at Connection.connect (/Users/xxxx/Documents/xxxx/Sites/Node/first/node_modules/mysql/lib/Connection.js:116:18)
    at Object.<anonymous> (/Users/xxxx/Documents/xxxx/Sites/Node/first/db_conn.js:10:5)
    at Module._compile (node:internal/modules/cjs/loader:1267:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1321:10)
    at Module.load (node:internal/modules/cjs/loader:1125:32)
    at Module._load (node:internal/modules/cjs/loader:965:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'xxxxx.hosting-data.io',
  fatal: true
}

Node.js v20.0.0

I appreciate this may be difficult to work on and i am sure there is info needed that i have not supplied but i am really struggling to get set up to work.

If anyone can help or can suggest resources to help me that would be very much apprecitated.

Thanks, As always.

Edited by requinix
redacting another instance of the domain name
Link to comment
Share on other sites

  • 1 month later...

Based on the error message you provided, it seems that the hostname xxxxxxx.hosting-data.io cannot be resolved. This could be due to a few potential reasons:

Incorrect hostname: Please double-check that the hostname you are using is correct. Ensure there are no typos and that the hostname corresponds to the correct database server provided by ionos.

Network or DNS issues: The error ENOTFOUND suggests that the hostname cannot be found. This could be caused by network connectivity issues or DNS resolution problems. Ensure that your network connection is stable and try running the code again. You can also try using a different network or DNS server to see if that resolves the issue.

Firewall or security restrictions: It's possible that there are firewall rules or security restrictions in place that prevent your Node.js application from accessing the specified hostname or port. Check if there are any network-level restrictions in your environment, such as firewall settings, that might be blocking the connection.

Additionally, make sure you have installed the mysql package by running npm install mysql in your project directory. This command installs the MySQL driver for Node.js, which is necessary for establishing a connection with the MySQL database.

If you continue to experience issues, it might be helpful to consult with your hosting provider (ionos) for further assistance and ensure that you have the correct hostname, port, username, and password for connecting to the MySQL database.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.