Skip to content

OPTIMIZE

OPTIMIZE TABLE Employees
+--------------+----------+----------+--------------------------------+
| Table | Op | Msg_type | Msg_text |
+--------------+----------+----------+--------------------------------+
| mydb.employees | optimize | status | Table is already up to date |
+--------------+----------+----------+--------------------------------+

The OPTIMIZE TABLE command in MySQL is used to reclaim the unused space and to defragment the data file. In the example, the OPTIMIZE TABLE command runs on ‘Employees’ table. After executing the operation, it returns a table with columns: ‘Table’, ‘Op’, ‘Msg_type’, ‘Msg_text’ detailing operation’s status and message text. Here, message text “Table is already up to date” implies there was no need for optimization.