I am trying to connect to my google-cloud-sql instance using my node.js mysql module and I am unable to connect to it. I referred to the following links mysql docs and google getting started but could not understand what's going on.
我正在尝试使用我的node.js mysql模块连接到我的google-cloud-sql实例,我无法连接到它。我提到以下链接mysql docs和google入门但无法理解发生了什么。
var connection = mysql.createConnection({
acquireTimeout: 30000,
host : '35.184.77.86',
user : 'XXX',
password : 'XXX',
database : 'name',
});
connection.connect(function(err){
if (err) {
console.error(chalk.red('error connecting: ' + err.stack));
return;
}
console.log(chalk.green('connected as id ' + connection.threadId));
});
connection.query('SELECT * FROM likes', function(err, rows, fields)
{
if (err) {
console.log(chalk.red(err));
}else{
console.log(fields);
}
});
connection.end();
I am getting the following error while connecting.
连接时我收到以下错误。
error connecting: Error: connect ETIMEDOUT
at Connection._handleConnectTimeout (/Users/narenpalep/Desktop/javascript/Project_Portfolio/node_modules/mysql/lib/Connection.js:419:13)
at Socket.g (events.js:292:16)
at emitNone (events.js:86:13)
at Socket.emit (events.js:185:7)
at Socket._onTimeout (net.js:338:8)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)
--------------------
at Protocol._enqueue (/Users/narenpalep/Desktop/javascript/Project_Portfolio/node_modules/mysql/lib/protocol/Protocol.js:145:48)
at Protocol.handshake (/Users/narenpalep/Desktop/javascript/Project_Portfolio/node_modules/mysql/lib/protocol/Protocol.js:52:23)
at Connection.connect (/Users/narenpalep/Desktop/javascript/Project_Portfolio/node_modules/mysql/lib/Connection.js:130:18)
at Object.<anonymous> (/Users/narenpalep/Desktop/javascript/Project_Portfolio/db/db.js:11:12)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
Error: connect ETIMEDOUT
1 个解决方案
#1
0
Try running with the below code also check the connection and for the right IP. There might be internal firewall block between the server and the system
尝试使用以下代码运行也检查连接和正确的IP。服务器和系统之间可能存在内部防火墙块
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
#1
0
Try running with the below code also check the connection and for the right IP. There might be internal firewall block between the server and the system
尝试使用以下代码运行也检查连接和正确的IP。服务器和系统之间可能存在内部防火墙块
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});