How to find the number of rows inserted / deleted in MySQL

Is there a way to find out the number of rows inserted / deleted in a table in MySQL? Are these statistics stored somewhere in the database? If not, what is the best way to implement something to keep track of these statistics?


When I say how much, I mean for a certain period (the last 24 hours or since the server was released, or last week, etc.)

+4
source share
4 answers

When I need to track deleted things, I just don’t delete. I am modifying the value of a column that excludes it from normal user results. If space is a problem, you can install its contents, which you no longer need to fear.

You can insert COUNT ()

+2
source

What questions are you trying to answer by collecting these statistics? There may be easier ways to get the answers you are looking for.

0
source

Binary Log contains records of all requests that update or insert data. However, I do not know if it keeps the number of rows affected.

There is also a General Query Log that tracks all requested queries.

(Current information for MySQL 5.0. If you are using an older version of ymmv)

0
source

If I want to process the logging of my SQL queries, I have 2 options:

  • Enabling the MySQL Log Function on
  • Writing a custom trace class

I prefer to do number 2. Why?

Because it is more manageable. You can easily distinguish from INSERT DELETE UPDATE etc. Requests But this is not the only advantage of your own trace class, because creating trace files (called logs) simplifies administrative tasks. You can structure the trace output, put it in a separate database, save it in an XML or JSON file. You can order things the way you want.

0
source

All Articles