PHP implementation MySQL data table optimization and repair

Source: Internet
Author: User

<?PHP$link=mysql_connect("localhost", "root", "") or die("Errro:".)Mysql_error());mysql_query("Set Names UTF8");mysql_select_db("Database name",$link);/*Display Data Sheet related information $sql = "Show Table status", $res = mysql_query ($sql, $link), while ($row = Mysql_fetch_assoc ($res)) {$row = Array ([name] = = Table name [Engine] = table's storage engine [version] + = version [Row_format] + line format. For the MyISAM engine, this could be dynamic,fixed or compressed. Dynamic lines have variable line lengths, such as varchar or BLOB type fields.        A fixed row is a constant line length, such as a char and an integer type field. [Rows] = number of rows in the table.        For non-transactional tables, this value is accurate, and for transactional engines, this value is usually estimated [avg_row_length] and the average number of bytes per row included [Data_length] and the amount of data in the entire table (in bytes) [Max_data_length] = The maximum amount of data the table can hold [index_length] = index occupies disk space [Data_free] + for the MyISAM engine, the identity is allocated, but now        In unused space, and contains space for rows that have been deleted.        [Auto_increment] + the value of the next auto_increment [Create_time] and the creation time of the table [update_time] = The last updated time of the table [Check_time] = Use the check table or Myisamchk tool to examine the list's most recent time [Collation] = table's default character set and character collation [Checksum] = if the The checksum of the entire table's contents [create_options] + = All other options when the table was created [Comment] + contains additional information for the MyISAM engine, including comments Xu PeiNew, if the table is using the InnoDB engine, the remaining space of the actual table will be.    If it is a view, the comment contains the view typeface. )    }*/$sql= "OPTIMIZE table data table name";$res=mysql_query($sql,$link); while($row=Mysql_fetch_assoc($res)){    /** $row = Array ([Table] + = database. data table name [OP] + optimize [msg_type] = status [Msg_text] = = Table is already up to date)*/    if($row[' msg_type '] = = ' ERROR ' &&Strpos($row[' Msg_text '], ' repair ')!==false)    {        mysql_query(' REPAIR table data table name ',$link); }    }

PHP implementation MySQL data table optimization and repair

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.