MySQL – How to Download Slow Query Log on Google Cloud SQL

google-cloud-sqlMySQLslow-log

I'm having a difficult time locating the log file to download. When running

show global variables like '%slow%';

I can see it is located

/mysql/logs/slow.log

When I log into the instance though that path doesn't exist. Any ideas?

This is through google cloud sql and using mysql as the db.

Best Answer

After a lot of digging I found an answer. It is not perfect as the quality of data may need some massaging, but it works.

gcloud logging read projects/yourproject/logs/cloudsql.googleapis.com%2Fmysql-slow.log --format json| jq -rnc --stream 'fromstream(1|truncate_stream(inputs)) | .textPayload' > slow-log-timestamp.log