mysql - node.js 中 Google Cloud mySQL 的连接字符串是什么?

标签 mysql google-cloud-platform database-connection connection-string

场景如下: 我正在本地编写一个 node.js 应用程序,并希望它(而是 mySQL 模块)连接到在 Google Cloud Platform 上运行的 mySQL 数据库。

我无法获得正确的连接字符串并不断出现错误。 GCP 拥有数据库的两个名称——一个是我选择的,一个是生成的,一个更复杂。可能我应该将其中之一作为“数据库”提供到连接字符串中,主机可能是带端口的 IP 地址(或不是(?)),我不确定“用户”应该是什么,或者是否有必要. GCP 帮助页面或其他地方的信息不足。

tl;dr:我需要以下内容来将带有 mySQL 模块的 node.js 应用程序远程连接到 GCP 数据库:

var con = mysql.createConnection({
  host:"11.222.333.444:3306",
  user: "me"
  password:"passwo3d",
  database:"projectname-1528892969949:europe-west5:dbname"
});

谢谢!

最佳答案

原始连接字符串应该类似于:mysql://user:password@localhost:port/db

所以我认为您的代码应该类似于:

var con = mysql.createConnection({
  host:"11.222.333.444", <-- remove the port from your string
  user: "me"
  password:"passwo3d",
  database:"dbname" <--  you have it as the instance name .. its just suppose to be the DB name
});

您还可以尝试使用 cloud proxy setup 连接到实例.您的主机只是本地主机。

最后,您始终可以转到 GCP 控制台 -> 转到您的实例并打开一个 shell。我认为他们在那里打印出 gcloud cmd,您也可以从控制台复制值。

根据您推送代码的方式,您可能还需要更改 list 中的一些连接字符串。如果您可以分享这些,我可以进一步提供帮助。

关于mysql - node.js 中 Google Cloud mySQL 的连接字符串是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51755760/

相关文章:

MySQL如何在使用3个表时求和

mysql - 多对多关系中的查询

php - "A server timeout has occurred"将 Dreamweaver 连接到 MySQL 时出错

python - MQTT 连接在 Screen session 中不起作用

php - 如何使用依赖注入(inject)和接口(interface)创建连接类?

python - 整个 python 应用程序中的单个数据库连接(遵循单例模式)

c# - 如何使用php将UWP中的图像保存到MYsql中

elasticsearch - 用于GCP alpha和beta api的elasticsearch查询

tensorflow - 如何在谷歌计算引擎上运行 tensorflow GPU 容器?

android - 后连接或直接连接到数据库,哪种方式更有效、更安全?