My server keeps crashing from OOM errors cause by MySQL. I am convinced there is a query on this site that is wrong, too long and causes this issue. My server and MySQL logs show very little strain until the spike and issue happens. I would really, really like to identify this problematic query and fix the query. I feel like mysql tuning an otherwise good production server to survive a bad query, which I want to remove anyways, is a weird way to go about it.
I have slow query logs set up but this problem query never shows up in the log, I believe because the query never finishes, the server crashes first. How can I log or identify this problematic query?
FYI There were other queries on this site that caused this issue and I did identify them and fix them. They typically happened because of clauses like "BETWEEN ::startTime AND ::endTime" and by mistake, ::startTime was being set to 0, making the timespan huge.
I have been advised to use EXPLAIN, which I understand, the problem is I don't know what query to "EXPLAIN" :).
Any suggestions in how I can identify this query would be appreciated. Thanks!