使用 JDBC 将 Google 电子表格连接到 MySQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16049966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connecting Google Spreadsheets to MySQL w/ JDBC
提问by lcm
I have been digging deep to try and find the answer here and on Google...hopefully someone can help.
我一直在深入挖掘,试图在这里和谷歌上找到答案……希望有人能提供帮助。
What I am trying to do is connect to MySQL from a Google Spreadsheet script found here:
我想要做的是从此处找到的 Google 电子表格脚本连接到 MySQL:
https://developers.google.com/apps-script/jdbc#reading_from_a_database
https://developers.google.com/apps-script/jdbc#reading_from_a_database
First I set up the server following these instructions:
首先,我按照以下说明设置服务器:
https://help.ubuntu.com/community/JDBCAndMySQL
https://help.ubuntu.com/community/JDBCAndMySQL
I get this error: "Failed to establish a database connection. Check connection string, username and password. (line 2, file "Code")Dismiss"
我收到此错误:“无法建立数据库连接。检查连接字符串、用户名和密码。(第 2 行,文件“代码”)关闭”
Line 2 looks like this:
第 2 行如下所示:
var conn = Jdbc.getConnection("jdbc:mysql://65.65.65.65:3306/dbname", "user", "password")
var conn = Jdbc.getConnection("jdbc:mysql://65.65.65.65:3306/dbname", "user", "password")
Then I find out that there is a bug in the JDBC however it is due to Hostnames and the solution is to use the IP instead. I am already using the IP so I don't think this bug is
然后我发现 JDBC 中有一个错误,但这是由于主机名造成的,解决方案是改用 IP。我已经在使用 IP,所以我不认为这个错误是
Mentioned here: Google Apps Script - JDBC Connection Failed
此处提到:Google Apps 脚本 - JDBC 连接失败
在这里:“无法建立数据库连接。检查连接字符串、用户名和密码”背后的根本错误是什么。
Confirmed and detailed here: https://code.google.com/p/google-apps-script-issues/issues/detail?id=1856
在这里确认和详细:https: //code.google.com/p/google-apps-script-issues/issues/detail?id=1856
.......now I don't believe my problem is with the above mentioned bug. I think its due to mysql being only accessible via SSH?
.......现在我不相信我的问题出在上面提到的错误上。我认为这是因为 mysql 只能通过 SSH 访问?
If that is the case then what I believeI need help with is modifying my code to connect over SSH.
如果是这种情况,那么我认为我需要帮助的是修改我的代码以通过 SSH 连接。
Or maybe I am wrong and I need to explore making mysql public...but that just doesn't feel right.
或者也许我错了,我需要探索将 mysql 公之于众……但这感觉不对。
Any and all thoughts are more than welcome.
任何和所有想法都非常受欢迎。
采纳答案by lcm
Sigh...The solution was right in front of my face. I needed to grant the Google App Server IPs. Im sure you could add more code to connect over ssh and its more secure but this is fine for now.
叹息......解决方案就在我面前。我需要授予 Google App Server IP。我确定您可以添加更多代码以通过 ssh 进行连接,而且它更安全,但现在这很好。
Here are IP address range:
以下是 IP 地址范围:
216.239.32.0 - 216.239.63.255 64.233.160.0 - 64.233.191.255 66.249.80.0 - 66.249.95.255 72.14.192.0 - 72.14.255.255 209.85.128.0 - 209.85.255.255 66.102.0.0 - 66.102.15.255 74.125.0.0 - 74.125.255.255 64.18.0.0 - 64.18.15.255 207.126.144.0 - 207.126.159.255 173.194.0.0 - 173.194.255.255
216.239.32.0 - 216.239.63.255 64.233.160.0 - 64.233.191.255 66.249.80.0 - 66.249.95.255 72.14.192.0 - 72.14.255.255 209.85.128.0 - 209.85.255.255 66.102.0.0 - 66.102.15.255 74.125.0.0 - 74.125.255.255 64.18 .0.0 - 64.18.15.255 207.126.144.0 - 207.126.159.255 173.194.0.0 - 173.194.255.255
https://developers.google.com/apps-script/jdbc#accessing_local_databases
https://developers.google.com/apps-script/jdbc#accessing_local_databases
回答by erick barreat
I know this was a firewall issue but I am sharing in case others want a free JDBC tool that is able to pull in data into your Google Spreadsheet. You are able to create queries and refresh your content all in one tool.
我知道这是一个防火墙问题,但我分享一下,以防其他人想要一个能够将数据提取到您的 Google 电子表格中的免费 JDBC 工具。您可以在一个工具中创建查询并刷新您的内容。
You can find it here. Google Spreadsheet JDBC Connector
你可以在这里找到它。Google 电子表格 JDBC 连接器