简体   繁体   English

Google Cloud SQL 导入 - 错误:HTTPError 403:客户端无权发出此请求

[英]Google Cloud SQL import - ERROR: HTTPError 403: The client is not authorized to make this request

I trying to import a database stored in the Cloud Storage using the command:我尝试使用以下命令导入存储在 Cloud Storage 中的数据库:

gcloud sql instances import instance-name gs://connect-to-the-cloud-sql.appspot.com/my-cloud-sql-instance-backup

But, I am getting error:但是,我收到错误:

ERROR: (gcloud.sql.instances.import) HTTPError 403: The client is not authorized to make this request.

I've already logged in using:我已经使用以下方式登录:

gcloud auth login

Make sure the instance-name is correct.确保实例名称正确。 I had the same error, it went away as soon as I corrected the instance-name.我有同样的错误,只要我更正了实例名称,它就消失了。

I had this problem, my instance name was correct.我遇到了这个问题,我的实例名称是正确的。 Turns out I was in the wrong GCP project.原来我在错误的 GCP 项目中。 Make sure you switch to the correct [target] project or use the project argument:确保切换到正确的 [target] 项目或使用 project 参数:

gcloud sql instances export my-cloud-sql-instance gs://connect-to-the-cloud-sql.appspot.com/my-cloud-sql-instance-backup --project=<your target project>

In my case it was because the cloud sql instance service account didn't have the correct permissions on the storage bucket I was trying to import from.就我而言,这是因为云 sql 实例服务帐户对我尝试从中导入的存储桶没有正确的权限。

From the docs : 从文档

  1. Describe the instance you are importing to:描述您要导入的实例:

     gcloud sql instances describe [INSTANCE_NAME]
  2. Copy the serviceAccountEmailAddress field.复制serviceAccountEmailAddress字段。

  3. Use gsutil iam to grant the legacyBucketWriter and objectViewer Cloud IAM roles to the service account for the bucket.使用gsutil iamlegacyBucketWriter objectViewer的服务帐号授予legacyBucketWriterobjectViewer Cloud IAM 角色。

  4. Import the database:导入数据库:

     gcloud sql import sql [INSTANCE_NAME] gs://[BUCKET_NAME]/[IMPORT_FILE_NAME] \\ --database=[DATABASE_NAME]

It might sound too obvious, but your service account really may be missing access rights for importing data.这听起来可能太明显了,但您的服务帐户确实可能缺少导入数据的访问权限。 Check that it has correct cloudsql.instances.import policy installed on IAM&Admin page.检查它是否在 IAM&Admin 页面上安装了正确的cloudsql.instances.import策略。

New step by step:新的一步一步:

gcloud sql instances describe name-instance | grep serviceAccountEmailAddress

# output: serviceAccount:account@gcp-sa.com

gsutil iam ch serviceAccount:account@gcp-sa.com:roles/storage.legacyBucketWriter gs://bucket-destino
gsutil iam ch serviceAccount:account@gcp-sa.com:roles/storage.objectViewer gs://bucket-destino

# -----------en vm linux--gcp------------------------------------------------------------------------------------
gcloud init (id-project-bucket-destino hacer default en vm proyecto de bucket donde se guardara info)
gcloud config set project id-project-bucket-destino

gcloud sql export sql --project=id-project-instance name-instance gs://bucket-destino/sqldump.sql \
--database=name-database \
--offload

# ----------cron job in linux------------------------------------------------------------------------------------
#!/bin/sh

#make directory in Cloud storage

datedirect=$(date '+%d-%m-%Y')

echo $datedirect

touch file5

gsutil cp -r ./file5 gs://bucket-destino/$datedirect/

gcloud config set project id-project-bucket-destino

gcloud sql export sql --project=id-project-instance name-instance gs://bucket-destino/sqldump.sql \
--database=name-database \
--offload

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 客户端无权发出此请求——同时尝试通过 java 获取谷歌云 sql 实例 - The client is not authorized to make this request -- while trying to get google cloud sql instance by java Google Cloud SQL 中的导入是否有限制? - Is there a limit on the import in Google Cloud SQL? 错误 403:您的客户端没有在 python google 云模块中获取 URL 的权限 - error 403: Your client does not have permission to get URL in python google cloud module 将数据导入云 SQL 使用云 SQL 客户端连接结束 - Import Data into Cloud SQL Using Cloud SQL Client Connection Ended ERROR: (gcloud.sql.instances.describe) HTTPError 404: Cloud SQL 实例不存在,但确实存在? - ERROR: (gcloud.sql.instances.describe) HTTPError 404: The Cloud SQL instance does not exist, but it does exist? Google Cloud Vision PHP — 提出批量请求 - Google Cloud Vision PHP — Make Batch Request Jupyter Notebook 和 Gsheet 之间的连接 - 失败 - HttpError 403 错误 - Connection between Jupyter Notebook and Gsheet - Failed - HttpError 403 Error “HttpError”是否会导致 Google Cloud 可调用函数中的冷启动? - Do "HttpError"s cause cold starts in Google Cloud callable functions? Google Cloud - 错误报告客户端库 - Google Cloud - Error Reporting Client Libraries ETIMEOUT 错误 | 谷歌云 SQL 数据库与 NodeJS - ETIMEOUT error | Google Cloud SQL database with NodeJS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM