I’m using a Perl script to dump the contents of a MySQL db. The Perl module I’m using is CPAN’s DBI. Is there any way to tell if the state of the db has changed since the last dump so that I don’t need to re-dump the db?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If all your tables are using the InnoDB engine, my guess is that you can check innodb_buffer_pool_write_requests:
If there has been a write to any InnoDB table since the last time you checked it, that value will have increased.
There may be false positives. A quick check shows that that value increases during and after a:
But I believe that if any writes have occurred, this value must change. Check it before the previous dump begins and after the current dump completes and if its value remains the same and all your tables are InnoDB, the dumps should be identical.
That said…
If you need to dump an entire MySQL database and you are at all concerned about consistency, you almost certainly want to generate that dump with mysqldump:
or, if
SHOW TABLE STATUSshows that all your tables are using the InnoDB engine,which has the same effect but will probably lock your tables for a lot shorter period.
Trying to write your own script to get a consistent dump is almost certainly a bad idea for a lot of reasons. (It’ll be hard to know when you’ve succeeded; that means bugs are likely; bugs with consistency can have subtly destructive effects which are the worst; your script will be slower and probably use more RAM.)
By default,
mysqldumpemits its output in standard SQL. If you want to manipulate the data yourself, you can get tab-delimited output by adding--tab=filename.