MySQL data rollback for past 3 queries - mysql

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.

Related

Is there any way to rollback after commit in MySQL?

I did a big mistake that I updated a table without 'where' clause in MySQL :'(
It is auto-committed.
Is there any way to rollback from it?
No, there's no query that will "undo" a committed data-modifying query.
If you have a backup of the database, you can restore the backup and use DBA tools (in MySQL's case, it's mysqlbinlog) to "replay" all data-modifying queries from the logs since the backup back to the database, but skip over the problem query.
If you don't have a backup and all logs since the that backup, there's nothing you can do to recover the data.
Look up transaction logs. I'll update with more info but the logs may only stay around for a limited time so time is of the essence!
See: http://dev.mysql.com/doc/refman/5.0/en/point-in-time-recovery.html
If you have enabled mysql binlog and also it is of ROW based format, then you can get the value for each row before & after the update. Using that you can restore the table's state.

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.

Undo table updates in SQL Server 2008

I updated a table in my SQL Server 2008 by accident, I was updating a table from another by copying cell by cell, but I have overwritten the original table. Is there a way that I can restore my table contents as it was?
This tool says it can do it, a bit pricey though. There is a trial period, maybe that will be long enough to get your data back:
http://www.apexsql.com/sql_tools_log.asp?_kk=log%20explorer&_kt=49fb8026-ca7c-4c5e-bb06-99ee95393472&gclid=CPWP48T3i6ICFY1a2godtTS7UQ
No. If you commited the transaction, the only way to restore the original table is by getting it from your latest backup.
if you have only a backup then restore that to another database and move just the table over (this way no other tables will be affected). If you have also transaction log backups then you can also do a point in time restore
I've heard that there are some tools that might be able to undo certain actions in certain circumstances. Here's a link to an interesting article about how to minimize data loss in these circumstances and it includes links to some tools.
You might want to ask this question at ServerFault as well as some sysadmins might know better.
Check this link. It shows how to restore values using transaction log
https://www.experts-exchange.com/articles/28199/How-to-recover-deleted-rows-in-SQL-Server.html
The article shows how we can recover deleted data if it happens accidently. We can recover deleted rows if we know the time when data is deleted. We can achieve this goal using LSN ( Log Sequence Numbers ). It shows an example of restoring deleted rows by checking the transaction log with LSN values. For updates use 'LOP_MODIFY_ROW'.
After deleting rows check the log using the following query
Select [Current LSN] LSN], [Transaction ID], Operation, Context, AllocUnitName
FROM
fn_dblog(NULL, NULL)
WHERE Operation = 'LOP_DELETE_ROWS'
Based on the transactionID and number of rows affected, filter the result set. Then use RESTORE DATABASE to restore the values from log.
NOTE: It is best to do this restoration as soon as you realize the accidental modification/deletion. The more the operations happening in a database there is high probability that the transaction log values might get overwritten.

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

How to fetch the data from binary log 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