What does repair and optimize tables in PHP MyAdmin actually do? Sometimes I repair or optimize (normally both) my tables in PHP MyAdmin  Often it fixes a problem I'm having.  My question is what am I actually doing when I undertake these actions?

Is there any danger?  Is any data changed or moved?
Someone told me Optimize is...

Do you remember when we used to defrag HDDs? Table optimization is something similar to that. It restructures a table so that data pages are next to each other and releases unused pages. If you ever delete a large part of the table data, optimization shrinks the table file down to the proper size.