DQL 数据查询语言 IS (information_schema)
3.information_schema 统计信息库
1.介绍:
视图
1.安全: 只允许查询,不知道操作的对象是谁。
2.方便: 只需要简单的select语句即可使用。
2.作用:
1.方便我们做数据库资产统计
库/表:
个数
数据量(容量;行数)
每张表的数据字典信息
2.可以获取到server层状态信息
3.获取到InnoDB引擎层的状态信息
3.应用举例:
TABLES :
TABLE_SCHEMA: 表所在的库
TABLE_NAME: 表名
ENGINE: 表的引擎
TABLE-ROWS: 表的行数
AVG_ROW_LENGTH: 平均行长度(字节)
INDEX_LENGTH: 索引占用长度(字节)
TABLE_COMMENT: 表注释
-- 例子:
-- 1. 简单查询体验TABLES信息
SELECT * FROM TABLES;
-- 2. 所有业务库和表的名字.
SELECT table_schema , table_name
FROM information_schema.tables
WHERE table_schema NOT IN ('sys','information_schema','performance_schema','mysql');
-- 3. 统计每个业务库,表的个数和列表
SELECT table_schema , COUNT(table_name),GROUP_CONCAT(table_name)
FROM information_schema.tables
WHERE table_schema NOT IN ('sys','information_schema','performance_schema','mysql')
GROUP BY table_schema;
-- 4. 统计业务数据库的总数据量
SELECT SUM(table_rows * AVG_ROW_LENGTH+index_length)/1024 AS total_KB
FROM information_schema.tables
WHERE table_schema NOT IN ('sys','information_schema','performance_schema','mysql');
-- 5. 每个业务库分别统计数据量
SELECT table_schema,SUM(table_rows * AVG_ROW_LENGTH+index_length)/1024 AS total_KB
FROM information_schema.tables
WHERE table_schema NOT IN ('sys','information_schema','performance_schema','mysql')
GROUP BY table_schema
ORDER BY total_KB DESC ;
-- 6. top 3 数据量大的表
SELECT table_schema,table_name,(table_rows * AVG_ROW_LENGTH+index_length)/1024 AS table_kb
FROM information_schema.tables
WHERE table_schema NOT IN ('sys','information_schema','performance_schema','mysql')
ORDER BY table_kb DESC
LIMIT 3;
-- 7. 查询所有非INNODB的表
SELECT table_schema,table_name ,ENGINE FROM information_schema.tables
WHERE table_schema NOT IN ('sys','information_schema','performance_schema','mysql')
AND ENGINE <> 'innodb';
-- 8. 查询所有非INNODB的表 , 并且提出修改建议
SELECT
table_schema,
table_name ,
ENGINE ,
CONCAT("alter table ",table_schema,".",table_name," engine=innodb;") AS "修改建议"
FROM information_schema.tables
WHERE table_schema NOT IN ('sys','information_schema','performance_schema','mysql')
AND ENGINE <> 'innodb';
-- 9. 所有业务库和表的名字,并且生产备份语句
SELECT
table_schema ,
table_name ,
CONCAT("mysqldump ",table_schema," ",table_name," > /bak/",table_schema,"_",table_name,".sql") AS "备份"
FROM information_schema.tables
WHERE table_schema NOT IN ('sys','information_schema','performance_schema','mysql');
DQL 数据查询语言 IS (information_schema)的更多相关文章
- 八:SQL之DQL数据查询语言单表操作
前言: DQL数据库查询语言是我们在开发中最常使用的SQL,这一章总结了单表操作部分的常用查询方式 主要操作有:查询所有字段.查询指定字段.查询指定记录.带IN的关键字查询,范围查询,陪查询.查询空值 ...
- 九:SQL之DQL数据查询语言多表操作
前言: 一:数据准备 员工表emp 和部门表 dept 注意:我在录入员工表的时候,特意添加了两条没有部门的员工,他们的部门id对应为null; --分别创建部门和员工表,并实现一对多关系 DROP ...
- DQL 数据查询语言 select
1.select 1.select 单独使用 (1) 查询数据库的参数 查看端口: select @@port; 查看数据路径 select @@datadir; (2)调用内置函数 查看当前库 se ...
- MySQL数据库之DQL(数据查询语言)
1.MySQL之DQL查询AS CONCAT LIKE的使用 (1)select 列名1,列名2,...... from 表名 [where 条件] 查询所有字段用*,不带where条件的话,就会把表 ...
- 第六章 DQL 数据查询语言
一.select 简单查询命令 #1.查询表中所有的数据 mysql> select * from test.student; #2.查看所有数据之前,先查看数据量 mysql> sele ...
- DQL 数据查询语言
查询数据(SELECT) # 查询所有数据 - 很危险,数据量过大,容易导致内存溢出而宕机 mysql> select * from student; # 先查询数据总量,然后决定是否可以查询所 ...
- DQL数据查询语言——连接查询
--内连接 两种写法 等值连接select r.*,b.bummc from t_hq_ryxx r, t_hq_bm b where r.bumbm = b.bumbm select r.*,b.b ...
- DQL数据查询语言
--查询全表select * from t_hq_ryxx; --查询字段select xingm as 姓名 ,gongz as 工资 from t_hq_ryxx; --链接字段查询select ...
- DQL 数据查询语言 show
2.show show databases; 查看所有的库 show tables; 查看当前库的所有的表 show tables from database; 查看指定的库下的所有表 show pr ...
随机推荐
- sqlserver 找不到驱动,显示项目缺少class办法
maven使用 <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId> ...
- poi提取docx中的文字和图片
package com.fry.poiDemo.dao; import java.io.File; import java.io.FileInputStream; import java.io.Fil ...
- Flask-Restless初步了解
Flask-Restless是Flask框架的一个扩展库 1. 功能介绍 通过使用SQLAlchemy或Flask-SQLAlchemy框架定义的数据库模型,提供一个简单的ReSTful A ...
- 树状数据删除(TP5)
应用场景:类似上图中树状菜单,选中一级菜单 点击上方删除按钮 所有子菜单删除 以下是代码截图(代码基于 TP5)
- GDB can't continue if no space left
[root@premta ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda3 36G 36G 0 100% /tmpfs 1.5G ...
- 分析/proc/[pid]/maps中的各个内存区域的大小
cat maps | sed -e "s/\([0-9a-f]\{8\}\)-\([0-9a-f]\{8\}\)/0x\1 0x\2/" | awk '{printf(" ...
- 截取url参数
//获得参数(只对字母数字等有效,参数值为中文则不能传) function getQueryString(name) { var reg = new RegExp("(^|&)&qu ...
- Rendering Problems The following classes could not be found:- android.support.v7.internal.app.WindowDecorActionBar (Fix Build Path, Create Class)
如图出现如下的错误的时候,一般都是升级Androdi Studio 后导致的,引入库不全,或者其他 东西缺少 可以如下解决方案:
- web集群和分布式服务以及消息补偿机制几种方案
一.为什么要集群? 1.JavaEE项目,如果部署在一台Tomcat上,所有的请求,都由这一台服务器处理,存在很大风险: A:并发处理能力有限(一般单台服务器处理的并发量为250左右,超过250,可能 ...
- shell变量的间接引用