Optimize shell scripts for Mysql Data Tables

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.