【发布时间】:2020-02-16 09:49:32
【问题描述】:
我正在尝试从我的 Google App Maker 应用连接到 Google Cloud SQL 数据库。不幸的是,我的 IT 人员尚未将 Google App Maker 设置为默认使用 Google Cloud SQL,因此我尝试以与过去连接到外部 MySQL 数据库相同的方式连接到数据库,但它不适用于公共 IP 地址。
我创建了一个 Google Cloud SQL 数据库,并且能够使用公共 IP 地址从 MySQLWorkbench 连接到它。为了连接数据库,我必须添加家用计算机的 IP 地址。我不需要使用 SSL。
我为我的 Google App Maker 应用创建了一个 Google 服务帐户。然后,我将此服务帐户包含在包含 Cloud SQL 数据库的 Google 项目中。我为它分配了 Cloud SQL Admin 和 Cloud SQL Client 的权限。
我正在应用制作工具中使用此代码来尝试连接。这与我在其他外部 MySQL 数据库中使用的代码相同。 IP 地址 34.xx.xx.xx 是 Google Cloud SQL 实例概览页面中列出的公共 IP 地址。
// App Settings
// Important Note: This is for demo purposes only, storing passwords in scripts
// is not recommended in production applications.
// DB Credentials (you need to provide these)
var address = '34.xx.xx.xx';
var db = 'Kenco_IoT_Template';
var dbUrl = 'jdbc:mysql://' + address + '/' + db;
var user = 'real_username';
var userPwd = 'real_password';
我收到此错误消息:
“正在执行对数据源 ActivityTable 的查询:(错误):建立数据库连接失败。请检查连接字符串、用户名和密码。请参阅自述文件并编辑您的数据库设置!”
我的猜测是问题在于设置 Cloud SQL 数据库以接受来自 Google App Maker 的连接。最好的解决方案是启用 Cloud SQL 作为 Google App Maker 的默认设置,但我希望现在可以使用一些替代方案。
任何帮助表示赞赏。
【问题讨论】:
-
我想你可能需要授权appscript ip地址...你这样做了吗?developers.google.com/apps-script/guides/jdbc#other_databases
-
谢谢!!!我为 appscript 授权了 IP 地址范围。我还需要切换到使用 Jdbc.getCloudSqlConnection(url) 而不是 Jdbc.getConnection(url)。宾果游戏——完美运行!恢复营业:)
-
@STEMFabLab 您能否将解决方案发布为答案?这可能有助于让其他用户了解解决方案,以防他们面临同样的问题。谢谢! :)
标签: google-cloud-sql google-app-maker