default | grid-3 | grid-2

Post per Page

How to get the last 10 queries by table name in MySQL

Last 10 queries

I had a situation where I wanted to check if some SQL changes I made were working properly.

It involved a transaction with a bunch of queries. Yes I could verify the data but I wanted to visually see the queries that my scripts were generating.

Turning on the general query log was not an option for me because of the amount of queries that get run every second.

During my DB research I found MySQL’s performance schema.

This query here will show you the last 10 statements that were ran for a particular table in a particular database.

I did see that if you do not prefix your tables with the db name in your query you’ll have to remove the line that looks for the db table.

SELECT event_id, event_name, sql_text, timer_wait
FROM performance_schema.events_statements_history_long
ORDER BY timer_start DESC

MySQL’s performance schema tables look awesome. I feel like there is a lot of untapped awesomness there that I need to research to help me as a programmer as well as helping me when I wear by DBA hat.

No comments

Error Page Image

Error Page Image

Oooops.... Could not find it!!!

The page you were looking for, could not be found. You may have typed the address incorrectly or you may have used an outdated link.

Go to Homepage