gpt4 book ai didi

google-cloud-platform - 将 App Engine 连接到 Cloud SQL 访问被拒绝

转载 作者:行者123 更新时间:2023-12-04 10:35:06 25 4
gpt4 key购买 nike

我正在尝试让我的 Flask App Engine 项目读取存储在 Cloud SQL MySQL 5.7 数据库中的数据。出了点问题,因为我得到的只是 pymysql.err.OperationalError .我一直在按照这里的说明操作:https://cloud.google.com/sql/docs/mysql/connect-app-engine .

  • Cloud SQL Admin API 已启用。
  • 根据链接文件:

    App Engine uses a service account to authorize your connections to Cloud SQL. This service account must have the correct IAM permissions to successfully connect. Unless otherwise configured, the default service account is in the format service-PROJECT_NUMBER@gae-api-prod.google.com.iam.gserviceaccount.com.


  • 列出我的项目权限的 IAM 页面不包含上述格式的成员。 “App Engine 默认服务帐户”的格式为:my-project-name@appspot.gserviceaccount.com。此服务帐号具有 Cloud SQL 客户端和编辑者角色。
  • 虽然我的查询不成功,但每次尝试后我都会在日志查看器中记录:7183 [Note] Access denied for user 'www-data'@'cloudsqlproxy~xxx.xxx.xx.xx' (using password: YES)(IP 地址已编辑)。这有点令人困惑,因为“www-data”不是我在代码中指定的用户。
  • 用于连接的代码:
  • app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://' + ':' + db_user + '@/' + db_name + '?unix_socket=/cloudsql/' + connection_name

    我哪里出错了,我该如何解决?

    最佳答案

    当尝试连接到具有错误凭据的数据库时,此错误是 mySQL 错误。

    请验证您使用的值是否正确。

    如果您不记得数据库用户名和密码,您可以按照以下步骤在控制台上更改它,这些步骤也说明了 here

    • Go to CloudSQL console
    • Select your database
    • Go to users
    • next to the user select click on the three dots
    • And select Change password
    • Type the new password and click OK

    关于google-cloud-platform - 将 App Engine 连接到 Cloud SQL 访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60217436/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com