Access to Google Cloud SQL from application script

I want to know if there is a way using an application script to connect to my Google Cloud SQL DB to execute a query.

I read a lot of posts, and it seems that the only way to access the Cloud SQL database is to use the App Engine.

Does anyone know a solution? thank

+5
source share
4 answers

Yes, obviously, you can connect script applications with Google Cloud SQL via JDBC.

Connecting to a Google Cloud SQL instance from a Google Apps script: The Google Apps script has the ability to connect to databases via JDBC using the Jdbc service.

: , Google APIs Console. . . .

Google Cloud SQL: Script, getCloudSqlConnection. , getConnection, Google Cloud SQL.

var conn = Jdbc.getCloudSqlConnection("jdbc:google:rdbms://instance_name/database_name");

, MySQL.

:

function insert() {
  var fname="First Name"
  var lname="Last Name"
  var conn = Jdbc.getCloudSqlConnection("jdbc:google:rdbms://instance_name/database_name");
  var stmt = conn.createStatement()
  var query="insert into person(FNAME,LNAME) values('"+fname+"','"+lname+"')"
  stmt.execute(query)
  stmt.close()
  conn.close()
 }

: .

function read() {
  var conn = Jdbc.getCloudSqlConnection("jdbc:google:rdbms://instance_name/database_name");
  var stmt = conn.createStatement()
  var query="select FNAME, LNAME from person"
  var rs= stmt.executeQuery(query)
  while(rs.next()){
    Logger.log("First Name : "+rs.getString(1)+" , "+"Last Name : "+rs.getString(2))
  }
  rs.close()
  stmt.close()
  conn.close()
 }
+11

Google , , , SQL, . Java , , URL.

:

url = "jdbc:mysql://your_address?user=root"; 

IPv4, ( 000.000.000.00)

URL-, ? User = root ";

var conn = Jdbc.getConnection("jdbc:mysql://your_address/

add /db_name .

var conn = Jdbc.getConnection("jdbc:mysql://your_address/db_name", user, userPwd);

,

  1. Apps Script, .

+2

Now there is no solution to connect to the Google Cloud SQL database from GAS, and it is not clear when it will be introduced. Here is the problem in the tester and here is a discussion of this problem in the Google Cloud SQL Group.

0
source

I think the only way to connect to Google Cloud Sql DB is through AppEngine.

-1
source

All Articles