Google Apps Script Google sheets

Fetch Data from MYSQL to Google Spreadsheet

MYSQL is the most popular RDBMS. Also it is open-source and is being used by many tech giants like Google and Facebook. Today in this article we will see how to connect and fetch data from MYSQL to Google Spreadsheet. This is possible in Google Apps Script with JDBC connection. Just put the query in the Spreadsheet and get the result instantly in the same sheet, very similar to a desktop query browser. It is always handy to analyse data in a spreadsheet as there are tools available to plot graphs and to do some complex calculation.

Connect Spreadsheet to MYSQL

We have created a small interface in the spreadsheet where the first row contains the query. When the cell is edited, an onEdit trigger is fired and fetches the details for the query provided. The results get populated with the headers, just below the query, isn't it cool ! The query takes an SQL string. So you can provide all valid operations and commands that are supported in sql like join, aggregation etc. It displays all types of SQL errors in a particular cell, really handy for writing the queries.

Features

  • Connects the Spreadsheet with MYSQL database
  • Fetches data from DB
  • Populates  data in the sheet, which is easy to analyze
  • Supports all type of complicated queries
  • Fetches data from multiple tables as well
  • Display errors in a cell for quick debugging

Example of executed query in Spreadsheet

How to use ?

  • Go to file  → Make a copy
  • Open the copied file and close the original one
  • Go to Tools → Open script editor → Provide the DB details 
  • Go to trigger and create an onEdit trigger as shown in the image below