我们正在使用GoDaddy。我们想通过mysqljs和nodejs连接到远程mysql。它适用于本地服务器,但它不适用于实时服务器。我们总是收到同样的错误:
错误:连接ETIMEDOUT
连接到Db时出错
这是我的连接代码:
var con = mysql.createConnection({
domain: "http://domain.com/",
host: "domain.com",
port: 3306,
user: "username",
password: "password",
database: "databasename"
});
con.connect(function(err){
console.log(err);
if(err){
console.log('Error connecting to Db');
return;
}
console.log('Connection established');
con.query("SELECT * FROM users WHERE username='"+user+"' and password='"+pass+"' ", function(err, rows) {
if (err) throw err;
if (rows=='') {
alert('Wrong username or password');
}else {
$.each(rows , function(key,value){
if (value.username==user && value.password==pass) {
//window.location =('Home.html');
window.location =('cpanel.html');
}
});
}
});
});