[英]Running nodejs Script to create table from local machine terminates Cloud SQL connection
I am trying to run the command node createTable.js $DB_USER $DB_PW $DB_NAME $CLOUD_SQL_CONNECTION_NAME
from windows power shell as it is indicated in the Google cloud Platform nodejs samples for connecting to cloudsql from cloudrun using knex in this repository .我正在尝试从 windows power shell 运行命令
node createTable.js $DB_USER $DB_PW $DB_NAME $CLOUD_SQL_CONNECTION_NAME
命令,因为它在使用此存储库的 cloudrun 连接到 cloudsql的 Google 云平台 nodejs 示例中指示。
I have intalled and Started the Cloud SQL Proxy and followed all the instructions including adding service accounts in the sample.我已经安装并启动了 Cloud SQL 代理,并按照包括在示例中添加服务帐户在内的所有说明进行操作。 But each time I run the createTable.js script from power Shell, I get the following errors in Powershell:
但是每次我从电源 Shell 运行 createTable.js 脚本时,我都会在 Powershell 中收到以下错误:
When I inspect the logs, I get the following in Cloud SQL当我检查日志时,我在 Cloud SQL 中得到以下信息
"db=cloudsqladmin,user=cloudsqladmin FATAL: terminating connection due to administrator command"
“db=cloudsqladmin,user=cloudsqladmin 致命:由于管理员命令而终止连接”
I don't know what possibly could be causing the error.我不知道是什么可能导致错误。
PS: I have tried to connect to cloud SQL from Cloud console and this worked fine, However, When I try this from my local machine using Powershell, It shows the above error PS:我尝试从云控制台连接到云 SQL,这工作正常,但是,当我使用 Powershell 从本地计算机尝试此操作时,它显示上述错误
It looks like you're trying to connect to Cloud SQL using the instance's public IP address.您似乎正在尝试使用实例的公共 IP 地址连接到 Cloud SQL。 If you're connecting through the Cloud SQL Proxy, you should be connecting to
localhost
or 127.0.0.1
at whatever port the proxy is running on.如果您通过 Cloud SQL 代理连接,您应该在代理运行的任何端口连接到
localhost
或127.0.0.1
。 To launch the proxy in TCP mode, run:要在 TCP 模式下启动代理,请运行:
Start-Process -filepath "C:\<path to proxy exe>" -ArgumentList "-instances=<project-id>:<region>:<instance-name>=tcp:5432 -credential_file=<CREDENTIALS_JSON_FILE>"
Then run然后运行
$env:DB_USER $env:DB_PW $env:DB_NAME $env:CLOUD_SQL_CONNECTION_NAME node createTable.js --dbHost "127.0.0.1:5432"
The proxy allows you to connect to your instance without having to add your machine's IP to the instance's allowlist.该代理允许您连接到您的实例,而无需将您机器的 IP 添加到实例的允许列表中。 If you try to connect directly and your IP isn't on the allowlist, you'll get an error.
如果您尝试直接连接并且您的 IP 不在允许列表中,则会收到错误消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.