'How do I Connect Google Sheets To MySql 8.0?
I'm working with this code to connect Mysql with google sheets through App Script.
var server = '11.11.11.11';
var port = 3306;
var dbName = 'dummy';
var username = 'username';
var password = 'password';
var url = 'jdbc:mysql://'+server+':'+port+'/'+dbName;
function readData() {
var conn = Jdbc.getConnection('jdbc:mysql://' + 'IP' + ':Port/' + 'dbname', 'username', 'password');
var stmt = conn.createStatement();
var results = stmt.executeQuery('SELECT * FROM dashboard_dummy');
var metaData=results.getMetaData();
var numCols = metaData.getColumnCount();
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Sheet1');
sheet.clearContents();
var arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(metaData.getColumnName(col + 1));
}
sheet.appendRow(arr);
while (results.next()) {
arr=[];
for (var col = 0; col < numCols; col++) {
arr.push(results.getString(col + 1));
}
sheet.appendRow(arr);
}
results.close();
stmt.close();
sheet.autoResizeColumns(1, numCols+1);
}
I am trying to connect a MySQL database with a google sheet to be able to automate the flow of live data. But within the google app script, I can't seem to establish a database connection. I get this -
Error
Exception: Failed to establish a database connection. Check connection string, username and password.
I just have my database on MySql workbench and popsql, but I'm completely lost as to how I should go about the next steps in making the connection. New to building databases in general so any help is appreciated!
Also, I've looked into whitelisting, but as a complete beginner, I have no idea how to whitelist IPs if it's a connection issue. I haven't found a single answer online!
(PS - I obviously changed the default parameters given within the code to my own, and I quadruple-checked them for mistakes but everything is exactly as my database.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
