MySql clients are using or haven’t closed the table properly


I have a database with about 65 tables. One of the tables is a large MyISAM table called order_line. Now and then this table is corrupt. When I use the CHECK TABLE command I get the messages:

Op    | Msg_type | Msg_Text
check | warning  | "Table is marked as crashed"
check | warning  | "3 clients are using or havent's closed the table properly"
check | error    | "Found 1149921 keys of 114948"
check | error    | "Corrupt"

I read a lot of this on the internet the most common answer is "you should repair the table". That works for me, but I want to know what the REASON is why this happens and also how can I reproduce this.

I have a webapplication and we have one database per customer (300+). We run scripts to update all these databases. I'm affraid when I do this, a lot of these tables get corrupt.

I also want to know what the best way is to update all these databases. Do I have to shut down MySQL and start it again to make sure no user is using the tables / databases?

Best Solution

I personaly repair my database by followings commands in mysql myDatabase.

CHECK TABLE myTable ; 
CHECK TABLE myTable ; 
--- OK