如何从 Google App Maker 连接到 Google Cloud SQL 数据库作为外部 mysql 数据库?
How can I connect to Google Cloud SQL database as an external mysql database from Google App Maker?
我正在尝试从我的 Google App Maker 应用程序连接到 Google 云 SQL 数据库。不幸的是,我的 IT 人员尚未将 Google App Maker 设置为默认使用 Google Cloud SQL,因此我正在尝试以与连接到的方式相同的方式连接到数据库过去的外部 MySQL 数据库,但它不能使用 public IP 地址。
我已经创建了一个 Google 云 SQL 数据库,我可以使用 public IP 地址从 MySQLWorkbench 连接到它.为了连接数据库,我必须添加家用计算机的 IP 地址。我不需要使用 SSL。
我为我的 Google App Maker 应用程序创建了一个 Google 服务帐户。然后,我将此服务帐户包含在包含 Cloud SQL 数据库的 Google 项目中。我为它分配了 Cloud SQL Admin 和 Cloud SQL Client 的权限。
我在 App Maker 中使用此代码尝试连接。这与我在其他外部 MySQL 数据库中使用的代码相同。 IP 地址 34.xx.xx.xx 是 Google 云 SQL 实例的概述页面中列出的 public 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';
我收到此错误消息:
"Executing query for datasource ActivityTable: (Error) : Failed to establish a database connection. Check connection string, username and password. Please refer to the ReadMe and edit your database settings!"
我猜问题出在设置 Cloud SQL 数据库以接受来自 Google App Maker 的连接。最好的解决方案是启用 Cloud SQL 作为 Google App Maker 的默认设置,但我希望现在可以使用一些替代方案。
感谢任何帮助。
要将此作为答案以便其他人可以更轻松地找到它:
答案是您需要将 appscript 的 IP 范围列入白名单。 Public 云上的 IP SQL 实例需要将 IP 地址列入白名单才能访问,或者它们需要使用云 SQL 代理。
OP 还提到他们必须将使用的 Jdbc 方法从 getConnection() 切换到 getCloudSqlConnection()。
我正在尝试从我的 Google App Maker 应用程序连接到 Google 云 SQL 数据库。不幸的是,我的 IT 人员尚未将 Google App Maker 设置为默认使用 Google Cloud SQL,因此我正在尝试以与连接到的方式相同的方式连接到数据库过去的外部 MySQL 数据库,但它不能使用 public IP 地址。
我已经创建了一个 Google 云 SQL 数据库,我可以使用 public IP 地址从 MySQLWorkbench 连接到它.为了连接数据库,我必须添加家用计算机的 IP 地址。我不需要使用 SSL。
我为我的 Google App Maker 应用程序创建了一个 Google 服务帐户。然后,我将此服务帐户包含在包含 Cloud SQL 数据库的 Google 项目中。我为它分配了 Cloud SQL Admin 和 Cloud SQL Client 的权限。
我在 App Maker 中使用此代码尝试连接。这与我在其他外部 MySQL 数据库中使用的代码相同。 IP 地址 34.xx.xx.xx 是 Google 云 SQL 实例的概述页面中列出的 public 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';
我收到此错误消息:
"Executing query for datasource ActivityTable: (Error) : Failed to establish a database connection. Check connection string, username and password. Please refer to the ReadMe and edit your database settings!"
我猜问题出在设置 Cloud SQL 数据库以接受来自 Google App Maker 的连接。最好的解决方案是启用 Cloud SQL 作为 Google App Maker 的默认设置,但我希望现在可以使用一些替代方案。
感谢任何帮助。
要将此作为答案以便其他人可以更轻松地找到它:
答案是您需要将 appscript 的 IP 范围列入白名单。 Public 云上的 IP SQL 实例需要将 IP 地址列入白名单才能访问,或者它们需要使用云 SQL 代理。
OP 还提到他们必须将使用的 Jdbc 方法从 getConnection() 切换到 getCloudSqlConnection()。