We have a 8 million row MySQL table. We want to prune about 2m rows from it, remove some outdated indexes and add new ones. To achieve almost no downtime, our plan is to create a clone of the table (and lock the original), run a script (Ruby) to prune the data that we don't need anymore and finally add the new indexes. Then we would put up the maintenance page on the web app, swap their names (by renaming the tables) and restart the app.
Is this the best way to achieve our final results? Any other tips/suggestions from people that have some something similar to this before? Whats the best way (super cool secret mysql cmds开发者_运维百科) to clone the table? Best/quickiest way to mass delete rows?
- All references use a view, not reading directly from
old_table
- Create new_table
- Select desired records into
new_table
, don't bring along records records to be deleted - Index
new_table
- Update view, replace
old_table
references withnew_table
- Rename
old_table
Deal with old_table when you want.
The real problem is new data during the transition process, which generally means downtime. Hopefully, you can just disable the ability to add data rather than take the entire site down.
精彩评论