有专门做宝宝用品的网站吗,火车头采集器网站被k,公众号链接制作,html5 手机网站导航条虚拟库字段讲解
#查看INFORMATION_SCHEMA的表信息
DESC information_schema.tables;
重要列#xff1a;
TABLE_SCHEMA #表所在的库
TABLE_NAME #表名
ENGINE #表的存储引擎
TABLE_ROWS #表的行数
DATA_LENGTH #表数据行占用的字节数
AVG_ROW_LENGTH #平均行长度
INDEX_LENGTH…虚拟库字段讲解
#查看INFORMATION_SCHEMA的表信息
DESC information_schema.tables;
重要列
TABLE_SCHEMA #表所在的库
TABLE_NAME #表名
ENGINE #表的存储引擎
TABLE_ROWS #表的行数
DATA_LENGTH #表数据行占用的字节数
AVG_ROW_LENGTH #平均行长度
INDEX_LENGTH #索引的长度
案例
例1查询mysql库中有哪些表
方法一从硬盘上查找
show tables from mysql;方法二从内存中查找
select table_name from information_schema.tables where table_schemamysql;例2统计mysql库的表数量
select count(table_name) from information_schema.tables where table_schemamysql;例3统计当前数据库服务器每个库的表数量
select table_schema as 库名,count(table_name) as 表数量
from information_schema.tables
group by table_schema;例4统计当前数据库服务器库的数量
select count(distinct table_schema) as 库数量
from information_schema.tables;注意事项
1.在企业应用中应排除系统库需要在where条件中增加如下下配置
where table_schema not in (mysql,sys,information_schema,performance_schema)
2.要解决交互问题能直接通过shell命令来查询出对应的结果
mysql -e select count(table_name) from information_schema.tables where table_schemamysql;例5统计world库每张表的行数
方法一
select count(*) from world.city;
select count(1) from world.city;方法二
select table_name,table_rows from information_schema.tables where table_schemaworld;例6统计world库每张表的大小
表索引数据
注释
AVG_ROW_LENGTH 表的平均行长度单位是字节
TABLE_ROWS 表的行数
INDEX_LENGTH 索引的长度单位是字节AVG_ROW_LENGTH*TABLE_ROWSINDEX_LENGTH select table_name as 表名,FORMAT((AVG_ROW_LENGTH*TABLE_ROWSINDEX_LENGTH)/1024,0) as 大小(KB)
from information_schema.tables
where table_schemaworld;例7统计每个业务库的大小select table_schema as 库名,FORMAT(SUM(AVG_ROW_LENGTH*TABLE_ROWSINDEX_LENGTH)/1024,0) as 大小(KB)
from information_schema.tables
where table_schema not in (sys,information_schema,performance_schema)
group by table_schema;例8统计当前数据库总数据select FORMAT(SUM(AVG_ROW_LENGTH*TABLE_ROWSINDEX_LENGTH)/1024,0) as 大小(KB)
from information_schema.tables;
concat拼接函数
案例环境单库单表备份
单库单表备份的命令如下
mysqldump world city /tmp/world_city.sql如果库名和表名都非常多那就导致这个操作重复次数多还需要手动填写库名和表名使用information_schema虚拟库配合concat函数可以实现快速生成单表备份的指令具体步骤
1.先修改配置文件让mysql支持可以输出结果到本地磁盘上
vim /etc/my.cnf
[mysqld]
...
secure-file-priv/tmp2.改完保存后重启mysqld服务让配置生效
systemctl restart mysqld 3.登入mysql来拼接备份指令并导出到本地脚本文件中
select concat(mysqldump ,table_schema, ,table_name, /tmp/,table_schema,_,table_name,.sql) from information_schema.tables where table_schema not in (sys,information_schema,performance_schema) into outfile /tmp/mysql_bak.sh;4.运行该脚本实现备份
sh /tmp/mysql_bak.sh