javascript - 将 nodejs 连接到谷歌云 SQL

标签 javascript mysql node.js google-cloud-sql

我正在尝试将 nodejs 实例连接到我的谷歌云 SQL 数据库。它失败了。

我运行命令

node server.js

得到错误

Problem with MySQL Error: connect ENETUNREACH

这是我的 server.js 文件

var gcloud = require("gcloud");
var express = require("express");
var mysql = require("mysql");
var app = express();
var connection = mysql.createConnection({
host : "2001:****:****:*:****:****:****:****",
user : "root",
password : "*****",
database : "scripto_5_k"
});
/* Connection to Database */
connection.connect(function(error){
if(error)
{
console.log("Problem with MySQL "+error);
}
else
{
console.log("Connected with Database ");
}
});
/*start the server */
app.listen(3000,function(){
console.log("its started on PORT 3000");
});

我已经在开发人员控制台访问了我的 sql 数据库,并允许我家的 ip 地址和 Node js 实例,但我似乎找不到问题。

非常感谢任何帮助。

更新 1

我用这个结果 ping 了 IPv6 地址

C:\Users\joe>ping 2001:****:****:*:****:****:****:****

Pinging 2001:****:****:*:****:****:****:**** with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 2001:****:****:*:****:****:****:****:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

但是我已经从gcloud的sql选项卡中的属性中获取了ip。

最佳答案

主机地址可能有误。你试过ping它吗?

关于javascript - 将 nodejs 连接到谷歌云 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30925856/

相关文章:

node.js - 在 TypeScript 中导入 Node.js npm 模块 (node_modules) 和声明

javascript - 检查网页上的文本框以获取特定字符串

node.js - 为什么 rxjs 一直不是正确的版本?

javascript - 使用 Node.js 进行异步字符串连接

php - 使用 laravel eloquent 搜索多个表

mysql select join 与 2 个不同的 ORDER BY

Mysql_install_db 找不到文件

node.js - 我想在特定时间后更改对象的值

javascript - 有没有什么方法可以代替 JS hack,让我可以从 iframe 发布到 iframe 之外的另一个页面?

javascript - ES6 类 setter 不被识别为函数