简体   繁体   English

运行 nodejs 脚本以从本地计算机创建表终止 Cloud SQL 连接

[英]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 致命:由于管理员命令而终止连接”

See attached image below:见下图: 在此处输入图像描述

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 代理连接,您应该在代理运行的任何端口连接到localhost127.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.

相关问题 NodeJS脚本在本地计算机上运行,​​但不在Firebase Cloud函数中运行? - NodeJS Script Runs on Local Machine but Not in Firebase Cloud Functions? 从本地机器上运行的 Node 应用程序访问 Google Cloud Datastore - Access Google Cloud Datastore from Node app running on local machine 从本地运行的 NodeJS / TypeORM 连接到 Google Cloud MySQL 实例 - Connect to Google Cloud MySQL instance from local running NodeJS / TypeORM 在本地计算机上运行的NodeJS和MAMP。 可能吗? - NodeJS and MAMP running on local machine. Is it possible? 尝试从Node.js创建SQL DB连接时出现连接错误 - Connection Error while trying to create SQL DB connection from nodejs NodeJs Express会话ID在本地计算机上保留,但在云服务器上重置 - NodeJs Express Session ID persists on Local Machine but resets on cloud server 您如何从本地计算机上的nodejs项目在Amazon EC2实例中运行Shell脚本? - How can you run a shell script in Amazon EC2 Instance from nodejs project in my local machine? 将文件从NodeJS Server下载到本地计算机 - Download file from NodeJS Server to local machine NodeJS + CloudSQL Postgres-连接随机终止 - NodeJS + CloudSQL Postgres - Connection terminates randomly 在本地机器上的 VSCode 中使用 NodeJS 运行带有层的 AWS Lambda - Running AWS Lambda with layers using NodeJS in VSCode on local machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM