Good day!
I'm trying to connect to a MySQL database using Node JS. I npm i'd mysql and included it on top of my file. When I run my code I get nothing. I did console logged the connection at the end of the script which gave me a valid connection model in return. I just never seem to reach the funciton within .connect nor the query or ping.
When I connect to localhost (running a Wamp server) the connection succeeds and I retrieve some console logs. I've tried connecting to a second external DB, giving me the same error.
The error I receive:
ETIMEDOUT. At Connection_handleConnectTimeout. And an error in protocol.js while handshaking Fatal true. (I omitted some text).
I have the latest mysql module installed.
var mysql = require('mysql');
var connection = mysql.createConnection({
host: 'MY_HOST_IP',
database: 'MY_HOST_DB',
user: 'MY_HOST_USR',
password: 'MY_PW'
});
connection.connect(function (err) {
console.log('conecting');
if (err) {
console.error('Error connecting: ' + err.stack);
}
console.log('Connected as id ' + connection.threadId);
});
connection.query('SELECT * from accounts', function (error, results, fields) {
if (error) console.log(error);
console.log('account ', results[0]);
});
connection.ping(function (error) { console.log('pingerror'); });
Edit:
The above code times out while connecting to either one of two externally hosted Databases (using their IP address). The hosts of these DB's say nothing is wrong with the settings. I try to connect from a 127.0.0.1:22005 connection towards the database, maybe there lies a problem? When I put above code in a stand alone JS file and run it with node in my commandline it connects.
from NodeJS Mysql module throws ETIMEDOUT error on remote DB
No comments:
Post a Comment