1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| # 切换进入information_schema数据库中查看表信息,此时看到的所有表信息,其实都是视图信息 use information_schema; show tables;
# 统计获取每个数据库中数据表的总数,以及表名称 select table_schema,count(*),group_concat(table_name) from information_schema.tables group by table_schema;
# 获取除了系统数据库之外的数据库中,数据表的总数,以及表名称 select table_schema,count(*),group_concat(table_name) from information_schema.tables where table_schema not in ('mysql','sys','performance_schema','information_schema') group by table_schema;
# 获取每个数据库数据占用磁盘空间 select table_schema,sum(table_rows*avg_row_length+index_length)/1024/1024 from information_schema.tables where table_schema not in ('mysql','sys','performance_schema','information_schema') group by table_schema;
# 获取具有碎片信息的表,碎片信息过多会导致索引信息失效,出现统计信息不真实的情况 select table_schema,table_name,data_free from information_schema.tables where table_schema not in ('mysql','sys','performance_schema','information_schema') and data_free >0 ;
# 处理具有碎片信息的表,其实就是把表的存储引擎改为InnoDB,也可以对已经是innodb存储引擎的表做此操作 select concat("alter table ",table_schema,".",table_name," engine=innodb") from information_schema.tables where table_schema not in ('mysql','sys','performance_schema','information_schema') and data_free >0 ;
# 获取数据库中非innodb表信息 select table_schema,table_name,engine from information_schema.tables where table_schema not in ('mysql','sys','performance_schema','information_schema') and engine!='innodb';
# 修改数据库中非innodb表信息替换成innodb,并将信息输出到文件中 select concat("alter table ",table_schema,".",table_name," engine=innodb;") from information_schema.tables where table_schema not in ('mysql','sys','performance_schema','information_schema') and engine!='innodb' into outfile '/tmp/alter.sql';
# 注意,如果遇到报错:ERROR 1290 (HY000): The MySQL server is running with the vim /etc/my.cnf [mysqld] secure-file-priv=/tmp # 修改配置文件参数信息,实现将数据库操作的数据信息导入到系统文件中,配置完毕重启数据库服务
|