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 7774187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:18:55+00:00 2026-06-01T17:18:55+00:00

I have a table with 15 million rows. At some point in the day

  • 0

I have a table with 15 million rows. At some point in the day I run a query that deletes about 2 million of those rows. It was taking about 30 minutes to run which as per the mysql admin was slowing down the replication for the whole instance.

I thought I could convert it in to a stored procedure that commits every 1000 rows but it seems replication still gets stuck until my whole stored procedure finishes. It would be possible to do the outside of mysql but I would really like to try and do this inside mysql. This is what I have…. Is there a way to make this more replication friendly.

BEGIN
   DECLARE rowcount INT;
   REPEAT   
      DELETE FROM tbl_sales_records WHERE salesFileNo = PassedInValue LIMIT 1000;
      SELECT ROW_COUNT() INTO rowcount;
      COMMIT;
   UNTIL rowcount=0
   END REPEAT;
END$$
  • 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-01T17:18:56+00:00Added an answer on June 1, 2026 at 5:18 pm

    One strategy I use for queries like this is to keep them out of the binary log, and run them separately on the replication master and the replication slave(s). That way they will not block the replication, assuming the delete does not cause any locks that block other statements.

    In order to do this you need to run the commands as a user with the SUPER privilege, and you need to be careful to make sure you delete the exact same data on the master and the slave(s) to avoid inconsistency but it can be a very useful technique.

    The key is to use the SQL_LOG_BIN setting to disable binary logging for the session in which you run the delete.

    For example:

    SET SQL_LOG_BIN = 0;
    DELETE FROM tbl_sales_records WHERE salesFileNo = PassedInValue;
    

    Or if you are using a stored procedure you can still disable binary logging the same way:

    SET SQL_LOG_BIN = 0;
    CALL your_delete_proc();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Problem I have a table that's about 2 million rows (at 115 MB)
I have a MySQL table with about 2 million rows, and a script that
I have a table with around 40 million rows, and I want to run
I have to delete about 10K rows from a table that has more than
I have a multi-million row table with a varchar field. Some of the rows
I have a table message in a database that has almost a million rows.
Lets say I have a table containing several hundred million rows that looks something
At work, I have a large table (some 3 million rows, like 40-50 columns).
We have a large table (450 million rows containing 34 columns of numeric or
I have a table with ~200 million rows and ~15 columns in it. I

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.