Ibanez1408
Ibanez1408

Reputation: 5058

Could not establish a connection to mySQL in Google Sheets

I am trying to connect to my mySQL Database using googel-appscript but I always get this error:

[16-08-31 10:28:17:156 HKT] Starting execution
[16-08-31 10:28:17:185 HKT] Jdbc.getConnection([jdbc:mysql://localhost:3306/ci_test, root, ]) [0.022 seconds]
[16-08-31 10:28:17:190 HKT] Execution failed: Failed to establish a database connection. Check connection string, username and password. (line 14, file "Code") [0.024 seconds total runtime]

Below is my simple code:

function DriveDashBoard(){
  var serverIP = 'localhost';
  var sqlPort = '3306';
  var sqlUser = 'root';
  var sqlPass = '';
  var sqlDB = 'ci_test';

  var connectorInstance = 'jdbc:mysql://' + serverIP+':'+sqlPort;
  var ConnectString = connectorInstance+'/'+sqlDB;

  var conn = Jdbc.getConnection(ConnectString, sqlUser, sqlPass);
}

I don't have password in the mySQL Database.

Upvotes: 0

Views: 184

Answers (2)

alfiethecoder
alfiethecoder

Reputation: 333

Yes. The server you're connecting to must be available on the public internet and preferably secured by only allowing access from Google's IP address ranges. localhost only works inside of your network.

Upvotes: 0

FG.
FG.

Reputation: 11

You just can't connect JDBC Google App to your mysql server on your LAN, at least you maka it exposed to Internet.

Upvotes: 1

Related Questions