Mysql--数据表碎片优化方法

一、优化步骤:


1.查看整库的情况
2.方便优化 3.整库所有表, 包含行数 索引长度 碎片空间 二、注意: 需要root权限或者服务器授予操作数据库权限 整理空间碎片 三、实施步骤: --回到需要整理空间碎片的数据库 use 库名;
OPTIMIZE
TABLE 数据表名 --空间碎片整理/也是主要目标
1) 使用库 use information_schema; (2)查询语句 英文 select table_name,table_rows,ENGINE,table_type,Avg_row_length,Data_length,Max_data_length,Index_length,Data_free from tables where TABLE_SCHEMA = 'ci_zhudai' order by table_rows desc; 中文 select table_name as '表名称',Table_schema as '表所属的库',Table_collation as '表的字符校验编码集',table_rows as '表存行数',ENGINE as '数据库引擎', table_type as '表类型',Avg_row_length as '平均行长度',Data_length as '数据长度', Max_data_length as '最大数据长度',Index_length as '索引长度',Data_free as '空间碎片',Table_comment as '表的注释' from tables where TABLE_SCHEMA = 'ci_zhudai_test' order by table_rows desc;

查询结果:
 
3)字段意义


字段
含义
Table_catalog
数据表登记目录
Table_schema
数据表所属的数据库名
Table_name
表名称
Table_type
表类型[system view|base table]
Engine
使用的数据库引擎[MyISAM|CSV|InnoDB]
Version
版本,默认值10
Row_format
行格式[Compact|Dynamic|Fixed]
Table_rows
表里所存多少行数据
Avg_row_length
平均行长度
Data_length
数据长度
Max_data_length
最大数据长度
Index_length
索引长度
Data_free
空间碎片
Auto_increment
做自增主键的自动增量当前值
Create_time
表的创建时间
Update_time
表的更新时间
Check_time
表的检查时间
Table_collation
表的字符校验编码集
Checksum
校验和
Create_options
创建选项
Table_comment
表的注释、备注

猜你喜欢

转载自www.cnblogs.com/mrszhou/p/9070184.html