简体   繁体   English

Node.js MySQL数据库连接-超时(ETIMEDOUT)

[英]Node.js MySQL database connection - time out (ETIMEDOUT)

I try to make a simple connection to an online mysql database on a node.js server. 我尝试建立到node.js服务器上在线mysql数据库的简单连接。 This is my code: 这是我的代码:

var mysql = require('mysql');

var con = mysql.createConnection({
    host: 'example.org',
    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". 每当我运行此服务器时,都会出现错误:“ 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). 我100%确信我的凭据正确无误,而且我还更改了phpmyadmin中用户的特权(我为该用户提供了所有可能的特权)。

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? -如何连接到该数据库?

Seemingly, 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). (默认值为10000)。

Just do: 做就是了:

var con = mysql.createConnection({
host: 'example.org',
    username: 'myusername',
    password: 'mypassword',
    connectTimeout: 30000
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM