无法使用 gcloud cli 创建 google 云 sql 实例,因为它花费的时间太长
Cannot create google cloud sql instance using gcloud cli because it is taking too long
我运行使用gcloud cli工具执行以下命令...
gcloud sql instances create sql-db-1 --database-version=MYSQL_8_0 --region=us-central --tier=db-f1-micro
它在终端中停留了很长时间,输出如下...
Creating new cloud sql instance...
然后最终失败...
ERROR: (gcloud.sql.instances.create) Operation https://sqladmin.googleapis.com/sql/v1beta4/projects/my-project/operations/0d9534c4-9c70-4a77-86a9-ae5c6d3b5fd8 is taking longer than expected. You can continue waiting for the operation by running `gcloud beta sql operations wait --project my-project 0d9534c4-9c70-4a77-86a9-ae5c6d3b5fd8`
Status : FAIL 1 b''
同样的命令对我来说很可靠,然后突然间它就开始这样做了。
您需要在本地 运行 云 SQL 授权代理来模仿云 运行 的作用。
- 下载最新版本here
- 确保您拥有一组有效的 gcloud 凭据(即
gcloud auth login
)
- 在终端中使用如下内容启动代理:
./cloud_sql_proxy -instances=my-project:my-region:my-instance -dir ./cloudsql
然后 Proxy 将在 ./cloudsql/my-project:my-region:my-instance
.
创建一个 Unix 套接字
注意:要使其最像 Cloud 运行,您始终可以在根目录下创建一个 /cloudsql
目录。
当您执行命令行时,它会创建 Cloud SQL 实例,但 CLI 会抛出一个错误,让您认为这不是创建的;所以我给你开了一个issue tracker report
同时你也可以运行在报错后:
gcloud beta sql operations wait --project my-project xxxxxxxxxxxxxxxxxxxxxx
并等待操作完成。之后,您必须看到 STATUS 为 DONE:
NAME TYPE START END ERROR STATUS
XXXXXXXXXXXXXXXXXXXXXXXXX CREATE 2022-03-09T21:53:40.532+00:00 2022-03-09T22:06:53.389+00:00 - DONE
当你打开这个link时出现错误:
https://sqladmin.googleapis.com/sql/v1beta4/projects/my-project/operations/0d9534c4-9c70-4a77-86a9-ae5c6d3b5fd8
您将获得:
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Login Required.",
"domain": "global",
"reason": "required",
"location": "Authorization",
"locationType": "header"
}
],
"status": "UNAUTHENTICATED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "CREDENTIALS_MISSING",
"domain": "googleapis.com",
"metadata": {
"service": "sqladmin.googleapis.com",
"method": "google.cloud.sql.v1beta4.SqlOperationsService.Get"
}
}
]
}
}
我运行使用gcloud cli工具执行以下命令...
gcloud sql instances create sql-db-1 --database-version=MYSQL_8_0 --region=us-central --tier=db-f1-micro
它在终端中停留了很长时间,输出如下...
Creating new cloud sql instance...
然后最终失败...
ERROR: (gcloud.sql.instances.create) Operation https://sqladmin.googleapis.com/sql/v1beta4/projects/my-project/operations/0d9534c4-9c70-4a77-86a9-ae5c6d3b5fd8 is taking longer than expected. You can continue waiting for the operation by running `gcloud beta sql operations wait --project my-project 0d9534c4-9c70-4a77-86a9-ae5c6d3b5fd8`
Status : FAIL 1 b''
同样的命令对我来说很可靠,然后突然间它就开始这样做了。
您需要在本地 运行 云 SQL 授权代理来模仿云 运行 的作用。
- 下载最新版本here
- 确保您拥有一组有效的 gcloud 凭据(即
gcloud auth login
) - 在终端中使用如下内容启动代理:
./cloud_sql_proxy -instances=my-project:my-region:my-instance -dir ./cloudsql
然后 Proxy 将在 ./cloudsql/my-project:my-region:my-instance
.
注意:要使其最像 Cloud 运行,您始终可以在根目录下创建一个 /cloudsql
目录。
当您执行命令行时,它会创建 Cloud SQL 实例,但 CLI 会抛出一个错误,让您认为这不是创建的;所以我给你开了一个issue tracker report
同时你也可以运行在报错后:
gcloud beta sql operations wait --project my-project xxxxxxxxxxxxxxxxxxxxxx
并等待操作完成。之后,您必须看到 STATUS 为 DONE:
NAME TYPE START END ERROR STATUS
XXXXXXXXXXXXXXXXXXXXXXXXX CREATE 2022-03-09T21:53:40.532+00:00 2022-03-09T22:06:53.389+00:00 - DONE
当你打开这个link时出现错误:
https://sqladmin.googleapis.com/sql/v1beta4/projects/my-project/operations/0d9534c4-9c70-4a77-86a9-ae5c6d3b5fd8
您将获得:
{
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"errors": [
{
"message": "Login Required.",
"domain": "global",
"reason": "required",
"location": "Authorization",
"locationType": "header"
}
],
"status": "UNAUTHENTICATED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "CREDENTIALS_MISSING",
"domain": "googleapis.com",
"metadata": {
"service": "sqladmin.googleapis.com",
"method": "google.cloud.sql.v1beta4.SqlOperationsService.Get"
}
}
]
}
}