2

Is it possible to auto delete data/row from my database after a certain time? eg. after 3months

I'am using phpmyadmin for my database.

AndroidNewbie
  • 669
  • 3
  • 16
  • 23

4 Answers4

4

You can schedule events in mysql.

Have a look on this http://dev.mysql.com/doc/refman/5.1/en/events.html

  • 1
    This is the best solution. phpMyAdmin supports interacting with the event scheduler by looking for the Event tab from within your database. Combine it with what Sutandiono said about having a field for knowing when a row was inserted so your code can figure out what to delete. – Isaac Bennetch Feb 08 '14 at 14:33
2

Yes, you can do the following:

  1. Ensure your data contain either insertion date, or the date when you want them to be deleted.
  2. Write a script to delete expired records.
  3. Put the script in a cron job, running once a day.
  4. ???
  5. Profit.

It's not related to phpmyadmin, btw.

Sutandiono
  • 1,748
  • 1
  • 12
  • 21
0

You can use CRON for that.

If you have a linux server, you can install crontab, and if not, you have some website like http://www.cronjobonline.com/..

Clément Andraud
  • 9,103
  • 25
  • 80
  • 158
  • Let me clarify this one sir. i dont have a linux server but i have a windows server. wherein my xampp is located. how to create website similar to cronjobonline? – AndroidNewbie Feb 07 '14 at 08:51
0

You can use MySQL events ..as

CREATE EVENT delete_class_data

ON SCHEDULE EVERY 7 DAY

DO

DELETE FROM <code>class</code>;

and delete specific data older than 7 days..are whatever you want. You can include date of entry in that table.