<?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