admin管理员组文章数量:1379351
I try to make a simple connection to an online mysql database on a node.js server. This is my code:
var mysql = require('mysql');
var con = mysql.createConnection({
host: 'example',
username: 'myusername',
password: 'mypassword'
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
Whenever I run this server I get the error: "connect ETIMEDOUT".
I am a 100% sure my credentials are correct and I also changed the privileges of the user in phpmyadmin (I gave this user all possible privileges).
I run the server locally, I am not sure if this has anything to do with it.
My questions are: - Why is it timing out? - And how can I connect to this database?
I try to make a simple connection to an online mysql database on a node.js server. This is my code:
var mysql = require('mysql');
var con = mysql.createConnection({
host: 'example',
username: 'myusername',
password: 'mypassword'
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
Whenever I run this server I get the error: "connect ETIMEDOUT".
I am a 100% sure my credentials are correct and I also changed the privileges of the user in phpmyadmin (I gave this user all possible privileges).
I run the server locally, I am not sure if this has anything to do with it.
My questions are: - Why is it timing out? - And how can I connect to this database?
Share Improve this question edited Jul 20, 2017 at 17:25 Siebrand Romeyn asked Jul 20, 2017 at 14:58 Siebrand RomeynSiebrand Romeyn 1521 gold badge1 silver badge9 bronze badges 2-
Error: connect ETIMEDOUT
in the connect callback indicates that the connection to the mysql server could not be established. Are you sure that thehost
you entered points to an ip the mysql server is listening to and that mysql ist listening to the standard port? – t.niese Commented Jul 20, 2017 at 17:36 - @t.niese At 'host' I put the URL of the webserver I host the MySQL database on. I also tried replacing the URL with an IP address but that didn't work either. – Siebrand Romeyn Commented Jul 20, 2017 at 18:33
1 Answer
Reset to default 5Seemingly, this is related to your DataBase server.
Though, you can try to extend the timeout default, by passing a longer timeout value. (Default is 10000).
Just do:
var con = mysql.createConnection({
host: 'example',
username: 'myusername',
password: 'mypassword',
connectTimeout: 30000
});
本文标签: javascriptNodejs MySQL database connectiontime out (ETIMEDOUT)Stack Overflow
版权声明:本文标题:javascript - Node.js MySQL database connection - time out (ETIMEDOUT) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744015535a2576255.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论