It is good practice in commercial systems to keep a log of operations(who/did what/when), this gives you the possibility to do:
- An audit in your system in case of direct or judicial request.
- History of operation. Your case.
- Get complementary information for partial backup restore due to system misuse.
As for the situation you find yourself in maybe the internal SQL log system can save you.
Binary log is a set of log files that contains information about the changes in the data made in the instance of the Mysql server.
The log is enabled by starting the server with the option --log-bin
. So the first thing you have to do is check how your server initializes the Mysql instance. Usually in enterprise instances or web provisioning this option is selected. In case of home servers or small office usually this option is waived.
If you have never used option --log-bin
I’m sorry but these dates are unrecoverable.
But if you’re lucky all your firm’s operations have been logged in to the mysql shell and type:
mysql> SHOW BINARY LOGS;
This command will display the Mysql operation log file set:
+---------------+-----------+
| Log_name | File_size |
+---------------+-----------+
| binlog.000015 | 724935 |
| binlog.000016 | 733481 |
+---------------+-----------+
To know which directory these files are in type:
mysql> SHOW VARIABLES LIKE 'datadir';
+---------------+---------------------------------------------+
| Variable_name | Value |
+---------------+---------------------------------------------+
| datadir | C:\ProgramData\MySQL\MySQL Server 8.0\Data\ |
+---------------+---------------------------------------------+
1 row in set (0.00 sec)
Go to this directory and use the tool mysqlbinlog to read the contents of the logs:
C:\ProgramData\MySQL\MySQL Server 8.0\Data\> mysqlbinlog binlog.000015
Each recorded operation starts with the date in the format ddyymm
and time.
You can create a Trigger to change the values of two columns like
criado_em
andultima_atualizacao
– rray
Good afternoon, thanks for the reply, could demonstrate/teach how I do this Rigger?
– ESP
I would recommend you save the date by your application and not by Rigger. The tables that you need to know the date that was inserted/updated you insert a column in this table to save the insertion/update date, and when entering a new record you send the date together.
– fajuchem
But he wants to rescue the date and time of the records that are already saved from a certain table that has no field recording date and time.
– Victor Carnaval
@Victorcarnaval In this case there’s no way.
– fajuchem