Restoring from backup and binary - mysql

There are times when a table / database is dropped unintentionally.
I have to check the date-time of the start position from the binary when the backup was taken.
I do also have to check the date-time of the position where the "drop" statement is found. I do run the mysqlbinlog statement with those parameters.
I can not use start-position and stop-position parameters because the binaries are spread across different files. Is there any better way to handle such human mistakes?

every time you take a backup, you should be using FLUSH TABLES WITH READ LOCK to force all of the tables in to a consistent state, followed by FLUSH LOGS to close the current binary log. then, when you apply the backup, all you have to do is replay one binary log.

Related

MySQL undo truncate table

One of my MySQL tables has been truncated by accident and I'd like to undo it so the data is returned. Is there a log anywhere I can view the data truncated or possibly get back the data?
I've read about MySQL binary log, where are they stored? The last backup I have is from 3rd of may but I'd like to get back the data that has been truncated if possible.
How do I solve: binary logs?
mysql_query("SHOW BINARY LOGS");
How do I view binary logs?
You can use the mysqlbinlog utility to view the content of the binary log if binary logging is enabled for your MySQL Server instance. It will dump the binary log as a SQL script.
You may still not be able to recover your data, as binary logs are sometimes a little tricky and contain just a few days of history.
I suggest that you read the documentation of the mysqlbinlog utility before attempting anything: https://dev.mysql.com/doc/refman/5.6/en/point-in-time-recovery.html

MySQL data rollback for past 3 queries

I just dropped my company's table and realized that the SQL backup I made was for STRUCTURE not DATA. I need to restore the data immediately.... is there anyway to do this? I'm using PHPMyAdmin and all i've done so far is
DROP TABLE USEFUL_TABLE
AND
CREATE TABLE IF NOT EXISTS USEFUL_TABLE
AND (IN DESPERATION)
ROLLBACK
Is there anyway to get the data records back?
Edit
Thanks for the comments, and thank God above that I found an obscure backup somewhere that I was able to restore! Just as a tip for anyone as hasty and careless as myself, BEFORE any backup/export operations, always make sure you've selected the Dump all rows option when exporting data for a backup. I didn't, and I didn't even check to confirm that the SQL had the rows dumped.
DDL commands can't be rolled back in MySQL. You need to restore from a backup.
If you need to recover data that was committed since the latest backup, perform point in time recovery with binary logs. But this depends on having binary logging enabled, and having a continuous set of binary logs since the date of the last full backup.

How to retrieve deleted records from MySQL

Is there any methods to retrieve deleted records from a mysql database?
No.
Deleted records are gone (or munged so badly you can't recover them). If you have autocommit turned on, the system commits each statement as you complete it (if you have auto commit turned off, then do a rollback NOW - phew, you're saved -- but you are running with autocommit, aren't you?).
One other approach is to reply the activity that created the missing records - can you do that? You can either re-run whatever programs did the updates, or replay them from a binary log (if you still have the binary log). That may not be possible, of course.
So you need to recover the data from somewhere - either a backup of your db (made using mysqldump) or of your file system (the data files of MyISAM tables are all simply structured and on the disk - recovering InnoDB tables are complicated by the shared use of ibdata files).
There is a possible way to retrieve deleted records (depending upon your situation). Please check here:
https://stackoverflow.com/a/72303235/2546381

Database dumping in mysql after certain checkpoints

I want to get mysqldump after certain checkpoint e.g. if i take the mysqldump now then next time when i will take the dump it should give me only the commands which executed between this time interval. is there anyway to get this using mysqldump.
One more thing how to show the commands delete, update in the mysqldump files.
Thanks
I dont think this is possible from a MySQLdump, however that feature exists as part of MySQL core - its called Binlogging or binary logging.
The binary log contains “events” that describe database changes such as table creation operations or changes to table data. It also contains events for statements that potentially could have made changes (for example, a DELETE which matched no rows). The binary log also contains information about how long each statement took that updated data
Check this out http://dev.mysql.com/doc/refman/5.0/en/binary-log.html
Word of warning, binlogs can slow down the performance of your server.

What is binlog in mysql?

I've set mysql parameter innodb_flush_log_at_trx_commit=0. It means that mysql flushes transactions to HDD 1 time per second. Is it true that if mysql will fail with this flush (because of power off) i will lose my data from these transactions. Or mysql will save them in data file (ibdata1) after each transaction regardless of binlog flush?
Thanks.
The binary log contains “events” that describe database changes such as table creation operations or changes to table data. It also contains events for statements that potentially could have made changes (for example, a DELETE which matched no rows), unless row-based logging is used. The binary log also contains information about how long each statement took that updated data. The binary log has two important purposes:
For replication, the binary log on a primary replication server provides a record of the data changes to be sent to secondary servers. The primary server sends the events contained in its binary log to its secondaries, which execute those events to make the same data changes that were made on the primary.
Certain data recovery operations require the use of the binary log. After a backup has been restored, the events in the binary log that were recorded after the backup was made are re-executed. These events bring databases up to date from the point of the backup
The binary log is not used for statements such as SELECT or SHOW that do not modify data.
https://dev.mysql.com/doc/refman/8.0/en/binary-log.html
Here is the entry in the MySQL reference manual for innodb_flush_log_at_trx_commit. You can lose the last second of transactions with the value set to 0.
Note that the binlog is actually something different that is independent of innodb and is used for all storage engines. Here is the chapter on the binary log in the MySQL reference manual.