MySQL / Google Cloud Platform Setup

In this run-through, I explore the setup of Google Cloud Platform (using MySQL), the Python code required to inject data into your MySQL DB and the visualization of this data in Google Data Studio

Creating a Cloud Database:

  1. You need a Google account for this...
  2. Go to Google Cloud Platform and click "Try it Free" - you get $300 to play with for 60 days (as of Feb 2017) but you still need to assign a payment method to it
  3. To the right of "Google Cloud Platform" you should see a small drop down, click it and choose "Create Project" and name it (NOTE: this is NOT the server name, it's the project name, so if you're going to add a few things under the same umbrella, such as "Performance", "Tests" etc, then name it accordingly here - I called mine "DatabaseTesting")
  4. It'll think for a bit....(~30 seconds)
  5. When it loads, choose "Create a Cloud SQL Instance"
  6. Click "Choose Second Generation" (this may be removed in the future and become the default)
  7. Give it a name. I called mine "thetechnicalartist" - I left everything else at the default
  8. It'll take a while for the instance to be created.....
  9. Click on the name of the instance to open the settings
  10. Click on "Databases" and then on "New database"
  11. I named mine "newstracker"
  12. Click on "Access Control" and create a new user that isn't you (i made mine without a password as this data isn't important)
  13. Download and install "MySQL Workbench" (choose custom when you install so you ONLY install the Workbench)
  14. Click the + next to "MySQL Connections"
  15. Enter:
    1. Connection Name: A name just for you in the control panel
    2. Hostname: the IP address of your instance
    3. Port: 3306
    4. Username: the user you added a moment ago in step 12
  16. Click "Test Connection"
  17. If it fails:
    1. This is probably an access control thing
    2. Click on your instance, then "Access Control", then "Add Network"
    3. Go to and find you IP address. Enter this in as the new network, and click "Save" and wait a moment
    4. Now test the connection in MySQL Workbench again
  18. In MySQL Workbench, click on the icon for your new connection at the top to open the editor
  19. On the left panel, expand the database name under "Schema", right click on "Tables" and choose "Create Table"
  20. Give it a name, and then add the columns we described earlier:
  21. Click "Apply" and execute the construction query
  22. The database is now setup and ready to accept data

Using Python to Connect to the Database

Now we have our database up and running in the cloud, let's try adding some test data to it via Python. We're making the assumption here that you're all set up with Python and an IDE

To do...

Cleaning Up The Code:

So far we've covered everything, but we need to wrap things up... so let's see what we can do

  • Add several more data sources (news site URLs)
  • Add a "nice name" for each URL for the purposes of presentation, as well as country names
  • Entry for each keyword
  • Wrap the injection with the data existence check
  • Comment everything

The script is set up to run on a scheduled task at 9AM every day.

So let's check back in a couple of weeks when we have a data set, and we can look at the visualization....

Data Visualization:

For this, we'll be using the fairly new (still in Beta) but free Google Data Studio.

  1. Go to Google Data Studio and click on "Data Sources" on the left
  2. Click the blue "+" in the bottom right
  3. Choose "Cloud SQL" from the list
    1. It may ask to authorize, do this with your Google login
  4. Enter your connection details and click "Authorize"
  5. For me, at this stage, I had "internal error", which suggested it couldn't connect. So I had to perform the following steps:
  6. Head over to your Google Cloud Platform and go to your database
  7. Click on "Access Control" and add the IP list from GDS Help to your white-listed networks
  8. Click Save and wait for it to finish
  9. After it connects, you should see your tables listed on the right
  10. Click on "Connect" at the top right
  11. Click "Create Report", then choose "Add t Report" on the popup (may need to authenticate again)
  12. Now you have your blank report. Click on "Untitled Report" to give it a name

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.