0

Suppose there is a database which contains a table that has date and events column, there are total 10 records now I want that the records which are older then the current date should automatically be deleted and the present date records should be present in the database so as the future records should also be present, does anyone know something like this or can help me how to achieve this. any references would be helpful. I am open to php, phpmyadmin, sql. Any help would be appreciated.

1

2 Answers 2

1

First it's too broad. You can consider using MySQL Event Scheduler for this purpose. Which you can set to run on every 24 hours and delete all records less than NOW()

Sign up to request clarification or add additional context in comments.

2 Comments

can you point some references or tutorials where I can learn this?
whenever I am trying to turn on event in phpmyadmin its saying I need super privileges to do that now how can overcome this?
0

Activate event support :

SET GLOBAL event_scheduler = ON;

Add sheduler :

DELIMITER |
DROP EVENT IF EXISTS `clear_old_rows`|
CREATE EVENT `clear_old_rows`
    ON SCHEDULE
    EVERY 1 HOUR STARTS CURRENT_TIMESTAMP
    ON COMPLETION PRESERVE
    ENABLE
    COMMENT 'clear all rows < CURRENT_TIMESTAMP'
    DO
    BEGIN
        DELETE FROM tablename WHERE date < CURRENT_TIMESTAMP ;
    END |
DELIMITER ;

2 Comments

whenver I try to activate event it says I need super privileges to do so now who i get that??
Must be logged in as root . mysql -u root -p'rootpass'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.