Register changes in Mysql

Asked

Viewed 150 times

0

Precise record all changes in the database, as UPDATE, INSERT and so on, so that I can restore the last backup and run queries from the last backup, manually deleting the unwanted wishes.

I read about the Binary log of Mysql, but it is possible delete the unwanted queries and open the log file in a user-friendly way for editing?

I need something like this:

-- [...]
-- 2017-04-11 22:07:32
UPDATE foo SET bar = 'fubá';
-- 2017-04-11 22:08:07
DELETE FROM tabela WHERE id = 127;
-- [...]

Use Mysql 5.7.14 in the Windows

1 answer

1


Good morning,

I need to record all changes in the database, such as UPDATE, INSERT and etc » I suggest you do it on your own, create a table log or similar to the information desired, such as date and time, description, operation performed and which user was. I have been doing this for several years and the logs have already saved me from typical situations like "lost the X client..."

Now, so that I can restore the last backup and run queries from the last backup it seems much more complicated. I suggest you schedule hourly, or optimum frequency, backup dumps and have these dumps as your Restore option.

but it is possible to delete unwanted queries and open the log file in a user-friendly way for editing? » I may be mistaken, but reading like this seems to me a solution "too magical" to solve a very complex situation. I would try with the backup dumps and, if necessary, have the queries in the log table and run them in a maintenance routine. But again, I would implement this via programming, for example in PHP.

I consider potentially dangerous to manually edit backup Sqls before making a Store, I try to avoid this type of approach.

Good luck!

  • So, @Fernandomertins, Imagine that I made a backup at 10am. After that have been executed several queries and one of these queries is unwanted. Suppose I restore the 10:00 backup and re-execute all the queries except the one I don’t want. If I log in text form, containing all queries, the application loses A lot of performance. If I schedule an x dump in x time, it will cost me a lot of disk space since I will have virtually identical data over and over again.

  • 1

    Good morning, I agree. Reading your explanation and trying to imagine the scenario, for example have made a backup at 10am. After that have been executed several queries and one of these queries is unwanted. it seems to me that you are trying to resolve the consequence (the unwanted query) in an inappropriate way, with backups. Maybe change the approach and make sure as much as possible that the unwanted query doesn’t get executed... :-) Idea, use a transaction, ask the user for one more confirmation before confirming the SQL statement, this kind of thing. Hugs!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.