patternsqlMinor
Lock database in time
Viewed 0 times
databasetimelock
Problem
I'm currently working with prototyping some stuff with a dump of a MySQL (5.7) database where much of the data is time dependent. Most of the queries I write use the
Is there a way to "lock the database in time" to the time of the dump or is there some other way to deal with this sort of situation, other than replacing all references to
NOW() function and the results change over time as we get further away from the time the dump was taken.Is there a way to "lock the database in time" to the time of the dump or is there some other way to deal with this sort of situation, other than replacing all references to
NOW() with a hard coded time stamp?Solution
You can use
Note that this will not affect
https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_sysdate-is-now
(People coming from the Oracle world know this parameter as
set timestamp which will make now() be fixed -- always return that value. See https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_timestampNote that this will not affect
sysdate(). To fix sysdate, you can start MySQL with the --sysdate-is-now option which will make sysdate() return the same value as now(), so in conjunction with above sysdate() will now be fixed. Seehttps://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_sysdate-is-now
(People coming from the Oracle world know this parameter as
fixed_date.)Context
StackExchange Database Administrators Q#227086, answer score: 4
Revisions (0)
No revisions yet.