What can be done to revert the old values ​​to the table after executing any update query?

What can be done to revert the old values ​​to the table after executing any update query?

I am using PHP and Mysql DB

+2


a source to share


2 answers


Default: nothing . There is no way.

If possible:

  • You were in a transaction (used BEGIN) and not COMMIT yet. You can then ROLLBACK.
  • You ran the instruction with AUTOCOMMIT set to 0. See above.
  • You have a recent backup of your row / table / schema / database . For example using MySQLDump.
  • You have the most recent backup of your filesystem where your database resides. For example, tape drives or a network adapter.
  • You have a log file with statements (like mysql query log or binary log). Then you can start with an empty table and rerun the commands that populated the table.
  • The database is mirrored on another system and the mirror has not been updated yet (fast ...)


But otherwise, no, sorry. Information is lost.

You should start thinking about doing one of the things mentioned above (backups are a MUST! Logging is recommended when developing if your server can handle it) to avoid these situations in the future.

+2


a source


If you are using transactions and have not committed a transaction, you simply rollback.

If you are not using transactions or have not completed a transaction, you are relying on one of:



  • props
  • application functionality, such as a trigger on a table, to register updates that allow you to restore old values.

There is no other built-in mechanism.

+4


a source







All Articles