开发者

How to fetch the data from binary log file and insert in our desired table in MySQL?

开发者 https://www.devze.com 2022-12-24 13:41 出处:网络
How to fetchthe data from binary lo开发者_Go百科g file and insert in our desired table in MySQL?

How to fetch the data from binary lo开发者_Go百科g file and insert in our desired table in MySQL?

I am on my way of scripting a PHP code for Audit Trail, in this I encountered a situation that if there will be new table created then I will not be available with triggers for that new table and hence no tracking could be done for that, so if I code it to create three new triggers for this new table, then how will get the last change done in this table? Hence I found that Binary Log File can be helpfull for me in this case, to fetch the last change for this new table and insert it in tracking table... BUT HOW????


If you're talking about the MySQL binary log file (mysql-bin), it wasn't designed to be read by anything other than MySQL - it's a transaction log file. The data in the log file will most of the time already be in your database by the time you read it.

Perhaps if you edit your answer to provide more information about what it is you're trying to achieve, you may get a better answer and solution.

EDIT:

Parsing the binary log file is going to give you more headaches - it's an internal file for MySQL and is known to change between releases. It also changes format depending on how the server is configured (row-based/statement-based/mixed format.) Server administrators can also disable binary logging completely.

If you can take the performance hit, you may be better off logging all queries - you can have these written to a file, or even to a database table (although in early versions of MySQL 5.1 there were severe performance hits for this; it may still be the case.) This logs all SQL queries received from clients, so you can check for the CREATE TABLE query and all statements amending data in this table.

http://dev.mysql.com/doc/refman/5.1/en/query-log.html

0

精彩评论

暂无评论...
验证码 换一张
取 消