Web Hosting Talk







View Full Version : mysql OPTIMIZE table - safe?


grabmail
12-31-2005, 08:50 AM
I'm thinking of optimizing all the tables in my mysql database every day because my script process a lot of deletions daily.

is it safe? mysql will lock the tables during optimization.

what if someone is executing a query against the table while i optimize it?

will it screw the table up?

i'm really worried about screwing up my db just because of optimizing

latheesan
12-31-2005, 10:50 AM
why dont u back it up first, then run ur optimization then. if it screws up, load ur backup database

if thats tedious, then temporarily turn ur site off with the notice, (we are under maintainence, we'll be back in few minutes). You can see this kind of methods in discussion boards, e.g. phpbb (maintainence mode)

hiryuu
01-01-2006, 07:35 AM
MySQL places a write lock on the table while optimizing, so any writes will block until the optimization is finished. Not sure about reads -- it rebuilds the table into a temporary table, so reads should be able to continue normally.

Burhan
01-01-2006, 09:53 AM
Another thing, you don't need to optimize your table every day. That's just not called for.