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

  • Home
  • SEARCH
  • 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 9145207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:27:25+00:00 2026-06-17T10:27:25+00:00

I have a main database that stores up to 5’000 new rows per day.

  • 0

I have a main database that stores up to 5’000 new rows per day.

I want to have a second database that only contains the latest 30 days worth of data at any time.

Therefore I plan to set up a cron job that regularly dumps the rows older than 30 days and copies the new ones.

What would be the best design for the copying part?

  • Copying on the fly with MySQL alone
  • An MySql export to a txt file, then an MySql import, then deleting the temporary file
  • A php script that iterates through the rows and copies them one by one

I want robustness and minimum amount of CPU/memory usage

  • 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-17T10:27:26+00:00Added an answer on June 17, 2026 at 10:27 am

    The quickest and most robust way is to perform the transfer directly in MySQL. Here are the steps involved:

    First, create the second table:

    CREATE TABLE IF NOT EXISTS second.last30days LIKE main_table;
    

    Next, insert the records 30 days old, or newer:

    INSERT INTO 
    second.last30days
    SELECT
    *
    FROM
    main_table
    WHERE
    created >= CURDATE() - INTERVAL 30 DAYS
    ORDER BY created;
    

    Lastly, delete the records older than 30 days:

    DELETE FROM 
    second.last30days
    WHERE
    created < CURDATE() - INTERVAL 30 DAYS
    ORDER BY created;
    

    It would be advisable to not run the INSERT and DELETE statements at the same time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our scenario: We have a main database that stores company-wide information. We have several
I have a SQL Server database with 500,000 records in table main . There
I have a SQL Server that houses Several Databases. I have a Main Database
I have a database, with several tables. The main table, called contacts , stores
I have main categories and sub categories. I want to be able to sort
I have main table called 'Employee' and another slave table called 'EmployeeTypes' that has
I have main.cpp (including main function) and func1.cpp, and I want to link these
Splash I have main activity UI startup operations that take between 5-10 seconds (that
I have a main-section div that is set to inherit it's height from its'
I have a text box in wxpython (see below) that stores the name of

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.