erotsppa
erotsppa

Reputation: 15071

How to find 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? Is this kind of statistics kept somewhere in the database? If not, what would be the best way to implement something to keep track of these statistics?


When I say how many, I mean within a certain period (last 24 hours, or since server was up, or last week etc)

Upvotes: 4

Views: 1463

Answers (3)

Julius F
Julius F

Reputation: 3444

If I want to handle logging my SQL queries, I have 2 possibilities:

  1. Turning the MySQL Log function on
  2. Writting my own 'trace' class

I prefer doing number 2. Why?

Because it is more controllable. You can easily differ from INSERT DELETE UPDATE and so on queries. But that is not the only advantage of your own trace class, because creating trace files (so called "logs") makes administrative tasks much more easier. You can structure the trace output, put it into a separate database, store it into some XML or JSON file. You can order things as you want them to be.

Upvotes: 0

Satanicpuppy
Satanicpuppy

Reputation: 1587

The Binary Log contains records of all queries that update or insert data. I don't know if it stores the number of affected rows, however.

There is also a General Query Log, which tracks all queries that were run.

(Information current for MySQL 5.0. If you're using an older version ymmv)

Upvotes: 0

Daren Schwenke
Daren Schwenke

Reputation: 5478

When I need to keep track of deleted things, I just don't delete. I change a column value that excludes it from normal user results. If space is an issue, you can set it's contents you no longer care about to empty.

Inserted you can user COUNT()

Upvotes: 2

Related Questions