Domanda

I have a small internal web app I'm developing with PHP and MySQL. I'm looking to sync client webpages to a server by requesting all changes since a certain date.

I've found a number of solutions for doing this via a 3rd party Change Data Capture library in MySQL (Maxwell, Debezium, etc.), but they all seem to stream to Kafka or something similar. This is a smaller, simple project without any sort of message queue/broker.

All I want is for changes to be recorded in the same MySQL database in a table with columns like the CRUD action, the table that changed, the table row ID, and the datetime. Then I could query for all rows changed since a certain date and time.

Is there a simple way or a library that can record this information right in the same MySQL database?

È stato utile?

Soluzione

The most obvious solution to this would perhaps be to use triggers. You can have triggers that fire before/after inserts, deletes and updates on the table(s) in question, and then log the changes in your special table, including a time stamp and what type of write operation it was.

Another approach could be to use an audit plugin - MariaDB's audit plugin works with older versions of MySQL at least up to 5.5. MySQL has Enterprise Audit, which presumably has a proprietary licence. These plugins will log to a file, but you can set up a cron job or similar to load that into a database table.

(With MariaDB 10.3+ you would be able to use system-versioned tables which would allow you to store all changes to rows.)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a dba.stackexchange
scroll top