[英]How to connect to mysql or postgresql database running on a cloud server with appscripts?
I am trying to connect to a postgresql
server, which is currently running on a google cloud machine
with appscripts
.我正在尝试连接到
postgresql
服务器,该服务器当前在带有appscripts
的google cloud machine
上运行。 I want to push the data from the google spreadsheet to that postgresql database, I have tried to achieve this with the help of jdbc
documentation provided in this documentation .我想将谷歌电子表格中的数据推送到 postgresql 数据库,我试图在本文档中提供的
jdbc
文档的帮助下实现这一点。 I have gone through the documentation but couldn't find anything related to postgresql, so i tried connecting with mysql database running on the same server but it is showing the error我浏览了文档,但找不到与 postgresql 相关的任何内容,所以我尝试连接在同一台服务器上运行的 mysql 数据库,但它显示错误
The code which I tried for connecting to mysql looks like
我尝试连接到 mysql 的代码看起来像
var server = 'ipaddress'
var dbName = 'dbname'
var username = 'db name'
var password = 'password'
var port = 3306
var url = 'jdbc:mysql://' + server + ":" + port + "/" + dbName;
function myFunction() {
var conn = Jdbc.getConnection(url, username, password)
Logger.log(url);
Logger.log(conn);
conn.close();
}
My current code for postgresql looks like我当前的 postgresql 代码看起来像
var dbName = 'dbname'
var username = 'username'
var password = 'password'
var port = 5432
function myFunction() {
var url = 'jdbc:postgresql://' + server + ":" + port + "/" + dbName;
var conn = Jdbc.getConnection(url, username, password)
Logger.log(url);
Logger.log(conn);
conn.close();
}
I am getting the error我收到错误
How to solve this?如何解决这个问题? and is it even possible to connect to postgresql with appscripts?
甚至可以使用 appscripts 连接到 postgresql 吗? PS I am able to connect to the same database with same credentials with pgadmin
PS 我可以使用 pgadmin 使用相同的凭据连接到同一个数据库
From Apps Script documentation here :来自此处的Apps 脚本文档:
The JDBC service supports Google Cloud SQL MySQL, MySQL, Microsoft SQL Server, and Oracle databases.
The JDBC service supports Google Cloud SQL MySQL, MySQL, Microsoft SQL Server, and Oracle databases.
So PostgreSQL is not yet supported.所以 PostgreSQL 还不支持。
For the MySQL connection, from the error message, it is clear that your credentials seems wrong.对于 MySQL 连接,从错误消息中可以清楚地看出您的凭据似乎错误。 Check it by login to your database remote server via terminal
通过终端登录到您的数据库远程服务器来检查它
mysql -u <username> -p -h <ip_address>
or connect it via Database Tools like DBeaver或通过DBeaver等数据库工具连接它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.