Mysql question in two parts

Discussion in 'Programming' started by wheel, Jul 26, 2007.

  1. #1
    I've got a big piggie Mysql database that I need to flush out, hoping someone can give me the mysql commands to do so.

    In one table I have a huge pile of records. Each record has a datestamp. What I want to do is delete all records prior to a certain date.

    Seems like I need three parts here (None of which I know how to apply to mysql);
    - convert a regular date to the funky datestamp that mysql uses
    - select all records where datestamp is less than some date I selected in the first step
    - delete all those records.

    Any babysitters out there :)? The table is like 2 gigs and it's giving my offsite backups a headache. TIA!
     
    wheel, Jul 26, 2007 IP
  2. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    MySQL can convert from UNIX timestamps itself.

    What you're after is something like:
    DELETE FROM `table` WHERE `date_column` < FROM_UNIXTIMESTAMP(some_unix_timestamp);
     
    TwistMyArm, Jul 27, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    I think he wants to convert a regular date to a timestamp.
    DELETE FROM `table` WHERE `date_column` < UNIX_TIMESTAMP('2005-12-31 23:59:59');
    Code (markup):
     
    krt, Jul 27, 2007 IP
  4. wheel

    wheel Peon

    Messages:
    477
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks folks. I believe that'll get it for me.

    I deeply appreciate the assistance.
     
    wheel, Jul 27, 2007 IP
  5. wheel

    wheel Peon

    Messages:
    477
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well, that seemed to have worked - but the file size is still over 2 gigs. Do I have to do some sort of flush command? Restarting mysql didn't change anything.
     
    wheel, Jul 29, 2007 IP
  6. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you have phpMyAdmin (well, even if you don't) you should be able to go into each table and under 'Operations', at the bottom of the screen, you should see 'table maintenance'. I'd read up on defragmenting and optimizing the tables then maybe use one of those...
     
    TwistMyArm, Jul 29, 2007 IP
  7. wheel

    wheel Peon

    Messages:
    477
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thank you....that did the trick. A quick google on 'optimize mysql' came up with this:
    So I logged into mysql and ran:
    OPTIMIZE TABLE tablename
    and that cut the size of the file down by over a gig. Not enough yet, but that's a big, big help.
     
    wheel, Jul 29, 2007 IP