I have MyISAM engine running in my cPanel server ,the server does not support InnoDB Engine, i only have MyISAM engine.
When i try to create a table column of type timestamp with a default value of (current time + 5 minutes) it gives an error.
This worked in my machine with InnoDB but in the server with MyISAM it gives an error You have an error in your SQL syntax; check the manual that... near DEFAULT (NOW() + 300)
CREATE TABLE test(
token_death_time TIMESTAMP DEFAULT (NOW() + 300)
);
I also tried
CREATE TABLE test(
token_death_time TIMESTAMP DEFAULT DATE_ADD(NOW(), INTERVAL 5 MINUTE)
);
Can I achieve what I want with MyISAM or I have to do the ‘adding’ in my PHP script?
3
Answers
You can use CURRENT_TIMESTAMP
To set desired timestamp as default, you can set it in variable and can use prepare & execute statement, use below code:
The DEFAULT value expression which you need is available for MySQL version 8.0.13 or later (fiddle – both queries are successfully executed on 8.0.19 version).
See Data Type Default Values.
And the issue is not relative to the table’s engine.
you cant use function for default value (before version 8)
but you can use trigger