MySQL Tables Altered?

Ovid on 2007-02-09T10:32:45

Anyone happen to know, offhand, how I can check to see if any table in MySQL has been altered? This is MySQL 4.1.15. Obviously "SELECT count(*) ..." could fail as could checking which keys are present in a given table. Something as simple as an UPDATE statement can easily foil both of those checks. I've tried 'SHOW STATUS ...', but that also fails. The only thing I can think of is to use a DBI trace to capture SQL and look for INSERT, UPDATE, or DELETE statements and try and parse them for the appropriate tables.

Google's given me no love on this problem.


Are you using InnoDB?

Adrian on 2007-02-09T10:52:55

In which case I think you're stuffed since AFAIK this bug is still open.

Add some triggers and doing it yourself would seem to be the obvious solution :-(

Re:Are you using InnoDB?

Ovid on 2007-02-09T11:16:18

Can't use triggers with this version of MySQL (as I'm sure you're aware). However, even though the tables are MyISAM, the Update_time is not being set for me which is why 'SHOW STATUS' seems virtually useless.

(God I hate MySQL)

logs?

vek on 2007-02-09T15:21:49

Does the database have logging enabled? With your version of MySQL, you can run mysqld with --log-update to capture any SQL statements that update data as described in the fine manual.

Calculating Mysql table checksums

gozer on 2007-02-10T01:28:41

With MySQL 5.x you have CHECKSUM TABLE, but it's only for MyIASM anyways.

http://dev.mysql.com/doc/refman/5.0/en/checksum-table.html

Check out this dude's elegant solution:

http://www.xaprb.com/blog/2007/01/25/how-to-calculate-table-checksums-in-mysql/

Triggers

bart on 2007-02-10T09:01:27

With triggers, and implementing journalling tables (storing and timestamping every change), this comes almost for free. It's a reason good enough for not using (that old version of) Mysql.

mtime

drhyde on 2007-02-10T12:24:25

Check the mtimes on the files containing the relevant tables?