I am trying to connect to an online hosted mysql database, so no localhost. But everytime i try to connect it gives me this error:
Error: connect ETIMEDOUT
at Connection._handleConnectTimeout (F:\FG\CO\CODESK\CO_PM\node_modules\mysql\lib\Connection.js:411:13)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at Socket._onTimeout (net.js:445:8)
at ontimeout (timers.js:427:11)
at tryOnTimeout (timers.js:289:5)
at listOnTimeout (timers.js:252:5)
at Timer.processTimers (timers.js:212:10)
--------------------
at Protocol._enqueue (F:\FG\CO\CODESK\CO_PM\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (F:\FG\CO\CODESK\CO_PM\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (F:\FG\CO\CODESK\CO_PM\node_modules\mysql\lib\Connection.js:118:18)
at condb (file:///F:/FG/CO/CODESK/CO_PM/dist/:59:16)
at HTMLDocument.<anonymous> (file:///F:/FG/CO/CODESK/CO_PM/dist/:23:5)
at j (F:\FG\CO\CODESK\CO_PM\node_modules\scripts\jquery.min.js:2:29999)
at k (F:\FG\CO\CODESK\CO_PM\node_modules\scripts\jquery.min.js:2:30313)
at e.invokeTask (file:///F:/FG/CO/CODESK/CO_PM/dist/polyfills.c6871e56cb80756a5498.js:1:7780)
at t.runTask (file:///F:/FG/CO/CODESK/CO_PM/dist/polyfills.c6871e56cb80756a5498.js:1:2964)
at t.invokeTask (file:///F:/FG/CO/CODESK/CO_PM/dist/polyfills.c6871e56cb80756a5498.js:1:8870)
This is the code used for the connection:
var mysql = require('mysql');
//login credentials have been replaced with placeholders
var connection = mysql.createConnection({
host : 'thehost',
user : 'theuser',
password : 'thepassword',
database : 'thedb',
});
connection.connect();
$clientquery = "SELECT * FROM fa_ec_clients WHERE pany_id = 'fc51b2dc49b0e4e76a90332f0e5cdafd'";
connection.query($clientquery, function (error, results, fields) {
if (error) alert(error);
console.log(results);
});
connection.end();
Is there anyone who has an idea how i could fix this?
I am trying to connect to an online hosted mysql database, so no localhost. But everytime i try to connect it gives me this error:
Error: connect ETIMEDOUT
at Connection._handleConnectTimeout (F:\FG\CO\CODESK\CO_PM\node_modules\mysql\lib\Connection.js:411:13)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at Socket._onTimeout (net.js:445:8)
at ontimeout (timers.js:427:11)
at tryOnTimeout (timers.js:289:5)
at listOnTimeout (timers.js:252:5)
at Timer.processTimers (timers.js:212:10)
--------------------
at Protocol._enqueue (F:\FG\CO\CODESK\CO_PM\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (F:\FG\CO\CODESK\CO_PM\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (F:\FG\CO\CODESK\CO_PM\node_modules\mysql\lib\Connection.js:118:18)
at condb (file:///F:/FG/CO/CODESK/CO_PM/dist/:59:16)
at HTMLDocument.<anonymous> (file:///F:/FG/CO/CODESK/CO_PM/dist/:23:5)
at j (F:\FG\CO\CODESK\CO_PM\node_modules\scripts\jquery.min.js:2:29999)
at k (F:\FG\CO\CODESK\CO_PM\node_modules\scripts\jquery.min.js:2:30313)
at e.invokeTask (file:///F:/FG/CO/CODESK/CO_PM/dist/polyfills.c6871e56cb80756a5498.js:1:7780)
at t.runTask (file:///F:/FG/CO/CODESK/CO_PM/dist/polyfills.c6871e56cb80756a5498.js:1:2964)
at t.invokeTask (file:///F:/FG/CO/CODESK/CO_PM/dist/polyfills.c6871e56cb80756a5498.js:1:8870)
This is the code used for the connection:
var mysql = require('mysql');
//login credentials have been replaced with placeholders
var connection = mysql.createConnection({
host : 'thehost',
user : 'theuser',
password : 'thepassword',
database : 'thedb',
});
connection.connect();
$clientquery = "SELECT * FROM fa_ec_clients WHERE pany_id = 'fc51b2dc49b0e4e76a90332f0e5cdafd'";
connection.query($clientquery, function (error, results, fields) {
if (error) alert(error);
console.log(results);
});
connection.end();
Is there anyone who has an idea how i could fix this?
Share Improve this question asked Nov 17, 2018 at 14:09 Wibo KuipersWibo Kuipers 832 gold badges2 silver badges11 bronze badges 5- It's the port 3306 enabled on the mysql host? Are you using Azure / AWS? Can you put the host url to check if the port is open? – Jose Mato Commented Nov 17, 2018 at 14:14
- @JoseMato Yes the port is enabled. but how can i find out if im using azure or AWS? – Wibo Kuipers Commented Nov 17, 2018 at 14:21
- Hummm,where did you find that "mysql database"? Is not managed by you? – Jose Mato Commented Nov 17, 2018 at 14:23
- @JoseMato it is managed by me. I have webshosting and that came with mysql databases. I use it a lot for my website using PHP and that works perfectly so i just do not get what te problem is here – Wibo Kuipers Commented Nov 17, 2018 at 14:32
- thanks for the info. That is weird. I am using the same mysql npm library and this error happens because of internal network problems (no access to internet, etc) or having access to internet but mysql port / your ip is filtered on destiny. Can you check two things please?: 1. try to connect using mysql from terminal and 2. Try to write a quick php script to connect to same remote host. If step 1 or 2 fails then there is a problem with the provider or with your network (trying from other network would be nice too if step 1 and 2 fails) – Jose Mato Commented Nov 17, 2018 at 14:48
2 Answers
Reset to default 4First of all, always check for an error return from .connect()
:
connection.connect(function(err) {
if (err) {
console.error('error connecting: ', err);
return;
}
});
It will be easier to tell what's wrong that way, and you maybe can even write your code to recover.
Secondly, your connection request times out. That means the host at thehost
is simply ignoring your request. Many hosting providers, especially those of the US$5 per month variety, only allow API access to their MySQL databases from within their own server farms. They configure their firewalls to ignore outside requests to internal-only services (like databases).
Some--not all--hosting providers offer a configuration setting to allow direct outside access to MySQL for their customers. You should look at their help documentation, or ask a customer support rep about this.
Why do they do this? Security and multitenancy: many customers share a single MySQL server, and if a cybercreep manages to break in to MySQL, he might be able to crash the server or steal data.
If it is on a VPS configured with CSF firewall, you need to whitelist your IP via SSH. Otherwise it still throws exactly above error even after adding via cPanel's Remote MYSql.
# csf -a <VPS-IP>
# csf -r
You can do it quickly via WHM too. Just posted as it may help somebody.