无法通过localhost将google apps脚本连接到mysql [英] Unable to connect google apps script to mysql through localhost

查看:316
本文介绍了无法通过localhost将google apps脚本连接到mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取错误:无法建立数据库连接。检查连接字符串,用户名和密码如果我运行以下脚本。我可以通过mysql工作台本地连接,但无法这样做与googleapp脚本。不知道我在哪里错了。如果我为电子表格写脚本,我需要设置触发器。

  function test(){
var conn = Jdbc.getConnection(jdbc:mysql://127.0.0.1:3306 / test,root,);
var stmt = conn.prepareStatement(SELECT * FROM info;);
var dbList = stmt.executeQuery();
dbList.next();
var row = 0;
Logger.log(Start of Log:);
while(dbList.next())
{
Logger.log(dbList.getString(1));
row ++;
}
}

谢谢。


<如果你是从家里做这个,想要运行google app脚本你的笔记本电脑上的本地MYsql数据库遵循以下步骤: -



1)将笔记本电脑上的3306端口公开到互联网。



登录到您的路由器并将3306端口转发到您的笔记本电脑: -
如果您拥有一个netgear路由器,这里是一个短的YouTube视频。基本上你在这里做的是;当谷歌脚本运行在谷歌服务器试图找到你的数据库,它命中路由器(公共IP)在端口3306.现在从那里这个请求路由到你的特定笔记本电脑。示例端口转发视频: -
端口转发视频



2)打开从任何计算机向任何拥有用户名密码的用户发送MYSql数据: -
在MySQL数据库上运行以下命令: -

 授予所有权限*。*至'username'@'%'IDENTIFIED BY'password'WITH GRANT OPTION; 

3)在以下行中使用您的公共IP地址: -
所以代替
var conn = Jdbc.getConnection(jdbc:mysql://127.0.0.1:3306 / test,root,);
使用以下

  var conn = Jdbc.getConnection(jdbc:mysql://127.0.0.1:3306 / test,root,); 

只是为了防止大家面对IPV6和JDBC兼容性问题。从以下地址获取您的公开IP地址: -
获取我的IPV4地址



因此,而不是127.0.0.1使用上述google查询的结果


Getting the error :"Failed to establish a database connection. Check connection string, username and password. " if I run the following script.I am able to connect locally through mysql workbench but unable to do so with googleapp script.Don't know where I am goin wrong .Also,do i need to set triggers if i write the script for a spreadsheet .

function test() { 
  var conn = Jdbc.getConnection("jdbc:mysql://127.0.0.1:3306/test", "root",""); 
  var stmt = conn.prepareStatement("SELECT * FROM info;"); 
  var dbList = stmt.executeQuery(); 
   dbList.next(); 
   var row = 0; 
  Logger.log("Start of Log:"); 
   while(dbList.next())
   { 
     Logger.log(dbList.getString(1)); 
     row++; 
   } 
  }

Thanks.

解决方案

Okay so if you are doing this from your home and want to run google app scripts your local MYsql database on your laptop follow the below steps:-

1)Expose port 3306 on your laptop to the internet.

Login to your router and port forward the 3306 port to your laptop:- Here is a short youtube video if you own a netgear router. Basically what you are doing here is; when the google script running on the google servers tries to locate your database it hits the router(public IP) on port 3306. Now from there this request gets routed to your specific laptop.Example port forwarding video:- Port Forwarding Video

2)Open up the MYSql data to anybody with a username and password from any computer:- run the following command on your MySQL database:-

GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

3)Use your public IP in the following line :- So instead of var conn = Jdbc.getConnection("jdbc:mysql://127.0.0.1:3306/test", "root",""); use the following

var conn = Jdbc.getConnection("jdbc:mysql://127.0.0.1:3306/test", "root","");

Just in case you face IPV6 and JDBC compatibility issues like most will. Get your public IP from the following address:- get my IPV4 address

So instead of 127.0.0.1 use the results from the above google query

这篇关于无法通过localhost将google apps脚本连接到mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆