Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8584055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:40:49+00:00 2026-06-11T21:40:49+00:00

I have a mysql table with 120 million rows and I want to write

  • 0

I have a mysql table with 120 million rows and I want to write a shell script to start purging some of that useless information in that table that’s not needed. Problem is I’m super new to shell scripting.

I have a datetime column with a unix timestamp in it. I want to delete every row that’s not within the last 2 months since I’ve recently enacted a data retention policy that will allow me to only keep 2 months of certain data.

TL;DR Need to build a shell script that deletes all rows up until the last 2 months of data by using the unix timestamp in the datetime column.

UPDATE: Here’s my new shell script

#!/bin/sh

i=1
while [ "$i" -ne 0 ]
do
  i=mysql -h 127.0.0.1 -u halo_ylh -pCa5d8a88 halo_twittstats < mysqlpurge.sql
  sleep 10
done
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:40:50+00:00Added an answer on June 11, 2026 at 9:40 pm

    Wouldn’t it be easier to just use the current_timestamp and unix_timestamp function to execute:

    DELETE FROM Table1 
     WHERE datetime < unix_timestamp(current_timestamp - interval 2 month)
    

    To run it from the shell you could put that command in a file script1.sql and run it using the mysql command line tool:

    mysql db_name < script1.sql
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database table and that table has 6 rows. What I want
I have a table in mysql that contains price field (around 500 rows in
I have mysql table that has a column that stores xml as a string.
I have a MySQL table and would like to return the rows based on
I have a MySQL table that looks something like this: +-----+------------+ | id |
I have a MySQL table with an auto-incremented integer primary key. I want to
I have a mysql table structure like that: id int primary key name varchar
I have a table in MySQL that have a few columns that have default
I have a table that lists people and all their contact info. I want
I have a function that updates a MySQL table from a CSV file. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.