How to enable slow query log on Google Cloud SQL for MySQL

In this post, we will quickly demonstrate how to enable Slow Query Log on Google Cloud SQL for MySQL.

  1. Open Cloud SQL Dashboard
  2. Click Edit on your Database
  3. Add 3 flags (a.k.a. configuration parameters) to your instance:
    • log_output - file / table / none
      We recommend to choose file, which will help you to quickly visualize and analyze your slow query using EverSQL
    • slow_query_log - On/Off
    • long_query_time - number, in seconds.
      For example, 1 means that the log will capture all queries that are longer than 1 second. 0 means capturing all queries
      If you just added or edited these three flags, you don't need to restart your instance, as these are dynamic configuration parameters:

View slow query logs on Google Cloud SQL

  1. Open Google Cloud Logs viewer
  2. Under the Logs field explorer, you will see your slow log file
    Google Cloud logs viewer - New Interface
    Google Cloud logs viewer - Classic Interface

Visualize and optimize slow queries from Google Cloud SQL

The next and final step will be to install EverSQL's Chrome extension - no configuration needed. Once you're done, you can navigate to the Logging tab in the Google Cloud logs dashboard, and start scrolling through the logs, or navigating to a specific point in time where you suspect a performance-related incident occurred.

Optimize your database, auto-magically.
Click to start, for free.

Once you found the queries you'd like to optimize, just click the Optimize with EverSQL button next to the query, and you'll be prompted with the query optimization recommendations and the optimal indexing suggestions, as in this example: