# Optimize Table

**URL:** <https://forums.percona.com/t/optimize-table/1545>\
**Category:** Other MySQL® Questions\
**Created:** [October 29, 2010, 8:24am UTC](https://forums.percona.com/t/optimize-table/1545 "2010-10-29T08:24:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmusleh](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@mmusleh](https://forums.percona.com/u/mmusleh)\
**Post date:** [October 29, 2010, 8:24am UTC](https://forums.percona.com/t/optimize-table/1545/1 "2010-10-29T08:24:53Z")

</div>

We have a table that contains 19 million records, 11 indexes + primary key, 16 columns

I’m trying to optimize it but I’m getting an error

I do  
OPTIMIZE NO\_WRITE\_TO\_BINLOG TABLE mytable;  
OR  
OPTIMIZE TABLE mytable;

it runs for 15-20 minutes then and I get  
ERROR 2013 (HY000): Lost connection to MySQL server during query

when I check the optimization result, I see nothing has changed

they way I check the optimization result is by checking the cardinality of all indexes before and after and I expect them to change after the optimization is done.

any ideas why I get that error? how can I optimize the table without getting that error msg?  
any help would be appreciated

Thanks

---

<div class="post-metadata">

**Author:** ![sterin71](https://avatars.discourse-cdn.com/v4/letter/s/5e9695/32.png) [@sterin71](https://forums.percona.com/u/sterin71)\
**Post date:** [October 29, 2010, 4:29pm UTC](https://forums.percona.com/t/optimize-table/1545/2 "2010-10-29T16:29:44Z")

</div>

Have you checked the error-log?

Do you have enough disk space on the data partition?  
An optimize table essentially creates a full ordered copy of the table during the optimization before throwing away the old unoptimized copy of the table.  
So if you run out of disk the optimization will not go through but MySQL will usually clean up the temporary tables.

Either way if there isn’t anything in the error-log you will have to monitor the server when you are running an optimize table to see what actually happens.
