Due to the large amount of data in the company's database, we regularly optimize the data tables in the company's mysql database (the optimize description is as follows). There are more than 300 data tables in the database, manual operations are obviously not realistic, and execution efficiency using scripts is still very good. The script is as follows: OPTIMIZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name [, tbl_name]… If you have deleted a majority of the tables, or if you have made many changes to the tables that contain variable-length rows (tables that contain VARCHAR, BLOB, or TEXT columns, optimize table should be used. The deleted records are kept in the Link List. Subsequent INSERT operations will reuse the old record location. You can use optimize table to reuse unused space and organize data file fragments. Usage: sh optimize. sh word [root @ shellec shell] ##! /Bin/shtime_log =/opt/optimize_time sum = $ # if ["$ sum"-eq 0] thenecho "Error: no parameter chosed" exit 1fi for I in $ *; doecho "optimize database $ I starting... "tables = $ (/usr/bin/mysql $ I-udevuser-pdevuser-e" show tables "| grep-v" Tables ">/opt/$ I) tablelist = $ (cat/opt/$ I) echo "optimize database $ I starting ................ ">>$ time_logecho" $ I start at $ (date + [% Y/% m/% d/% H: % M: % S]) ">>$ time_log for list in $ tablelistdoecho $ list/usr/bin/mysql $ I-utaobao-padmin-e" optimize table $ list "done echo" $ I end at $ (date + [% Y/% m/% d/% H: % M: % S]) ">>$ time_logecho >>$ time_logdone