从MySQL 5 开始 , 你可以看到多了一个系统数据库 information_schema . information_schema 存贮了其他所有数据库的信息。 information_schema是一个虚拟数据库,并不物理存在。Mysql的INFORMATION_SCHEMA数据库包含了一些表和视图,提供了访问数据库元数据的方式,这台MySQL服务器上,到底有哪些数据库、各个数据库有哪些表,每张表的字段类型是什么,各个数据库要什么权限才能访问,等等信息都保存在information_schema表里面. 让我们来看看几个使用这个数据库的例子
http://hudeyong926.iteye.com/blog/2380734
查询数据库dj214中表数据超过 1000 行的表
select concat(table_schema,'.',table_name) as table_name,table_rows from information_schema.tables where table_rows > 1000 and table_schema = 'dj214' order by table_rows desc;
查询数据库dj214 中所有没有主键的表
SELECT CONCAT(t.table_schema,".",t.table_name) as table_name FROM information_schema.TABLES t LEFT JOIN information_schema.TABLE_CONSTRAINTS tc ON t.table_schema = tc.table_schema AND t.table_name = tc.table_name AND tc.constraint_type = 'PRIMARY KEY' WHERE tc.constraint_name IS NULL AND t.table_type = 'BASE TABLE' AND t.table_schema = 'dj214' ;
查询所有数据库中10张最大表
SELECT concat(table_schema,'.',table_name) 表名称, concat(round(data_length/(1024*1024),2),'M') 表大小 FROM information_schema.TABLES ORDER BY data_length DESC LIMIT 10;
查看MYSQL数据库下所有的数据库
SELECT SCHEMA_NAME AS 'database' FROM INFORMATION_SCHEMA.SCHEMATA LIMIT 0 , 30
列出指定数据库中的所有表名称
SELECT table_name, table_type, engine FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'dj214' AND table_type='BASE TABLE'
列出指定数据库下指定表的表结构
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'systemlog' AND table_schema = 'dj214'
一段MYSQL存储过程 [ 删除指定库中所有的空表 ]
begin /*局部变量的定义,默认值为空 */ declare tmpName varchar(200) default '' ; /*定义游标*/ DECLARE reslutList Cursor FOR select table_name from information_schema.tables where table_rows <1 and table_schema = 'sz8_news' order by table_rows desc; declare CONTINUE HANDLER FOR SQLSTATE '02000' SET tmpname = null; OPEN reslutList;/*打开游标*/ FETCH reslutList into tmpname; -- 取数据 /* 循环体 */ WHILE ( tmpname is not null) DO set @sql = concat('drop table sz8_news.',tmpname,";"); PREPARE stmt1 FROM @sql ; EXECUTE stmt1 ; DEALLOCATE PREPARE stmt1; /*游标向下走一步*/ FETCH reslutList INTO tmpname; END WHILE; CLOSE reslutList; /*关闭游标*/ end
一段 MYSQL存储过程 [ 删除指定库下所有表中的空列,即表中的任何一条记录该列都没有值 ]
BEGIN DECLARE done INT DEFAULT 0; DECLARE cTbl varchar(64); DECLARE cCol varchar(64); DECLARE cur1 CURSOR FOR select TABLE_NAME,COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA='sz8_news' and IS_NULLABLE='YES' order by TABLE_NAME; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; set @sqlDrop=''; OPEN cur1; FETCH cur1 INTO cTbl, cCol;/*得到表名及列名*/ WHILE done = 0 DO set @x=0; /*主要改进了这里把空值也纳入判断条件中去,即如果字段为null或空*/ set @sql=concat('select 1 into @x from ',cTbl,' where ',cCol,' is not null and ',cCol,' !="" limit 1'); PREPARE stmt1 FROM @sql; EXECUTE stmt1; DEALLOCATE PREPARE stmt1; if @x=0 then set @sqlDrop=concat('alter table `',cTbl,'` drop COLUMN`',cCol,'`;'); PREPARE stmt1 FROM @sqlDrop; EXECUTE stmt1; DEALLOCATE PREPARE stmt1; end if ; set done = 0; FETCH cur1 INTO cTbl, cCol; END WHILE; CLOSE cur1; END
相关推荐
MySQL中information_schema是什么
MySQL中information_schema系统表
information_schema数据库是在mysql的版本5.0之后产生的,一个虚拟数据库,物理上并不存在。information_schema数据库类似与“数据字典”,提供了访问数据库元数据的方式,即数据的数据。比如数据库名或表名,列类型...
这个问题是微信群中网友关于MySQL权限的...FROM information_schema.tables t1 LEFT OUTER JOIN information_schema.table_constraints t2 ON t1.table_schema = t2.table_schema AND t1.table_name = t2.table_name
本文介绍了information_schema数据库的三张重要的表"schemata"、“tables”和“columns”在SQL注入中的应用思路。
Coinciding with the new native data dictionary in MySQL 8.0, we have made a number of useful enhancements to our INFORMATION_SCHEMA subsystem design in MySQL 8.0. In this post I will first go th
mySQL索引查看 select * from information_schema.statistics where table_schema='数据库名称' and table_name = '表名称'
新装的mysql里面有两个数据库:information_schema 和 mysql 。他们是干么用的?可以删除么?当然是不可以删除的。1.information schema 是mysql系统用的所有字典信息,包括数据库系统有什么库,有什么表,有什么...
通过Linux指令直接获取数据库和数据表信息: mysql -uroot -pxxxx -D information_schem
代码如下:select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),’ MB’) as data_size,concat(truncate(sum(index_length)/1024/1024,2),’MB’) as index_sizefrom information_schema.tables...
id=-1 ' union select 1,schema_name,3 from informaiton_schema.schemata --+ id=-1' union select 1,tbale_name,3 from information_schema.tables where table_name='security'--+ id=-1' union select ...
23. INFORMATION_SCHEMA信息数据库 24. 精度数学 25. API和库 26. 连接器 27. 扩展MySQL A. 问题和常见错误 B. 错误代码和消息 C. 感谢 D. MySQL变更史 E. 移植到其他系统 F. 环境变量 G. 正则表达式 H. Limits in ...
主要介绍了MySQL 8.0统计信息不准确的原因,帮助大家更好的理解和学习MySQL8.0的相关内容,感兴趣的朋友可以了解下
1.查看mysql数据库大小SELECT sum(DATA_LENGTH)+sum(INDEX_LENGTH)FROM information_schema.TABLES where TABLE_SCHEMA=’数据库名’;得到的结果是以字节为单位,除1024为K,除1048576(=1024*1024)为M。 2.查看表的...
,,,,,,,,,, ,mysql版本,数据库服务器的版本 ,VERSION,,version,,select * from information_schema.GLOBAL_variables where VARIABLE_NAME in('VERSION');,,,,, ,端口,所运行的数据库服务器的端口号,REPORT_PORT,,...
①.Mysql数据库的安装: 数据库的安装分为源码安装和rpm安装。 当然对于老手来说需要进行一些自定义的配置,那么当然源码安装的灵活性要高一些。 但是这种安装方式需要管理员自己处理好于系统的依赖关系。 而rpm安装...
一个简单的和改进的实施一些INFORMATION_SCHEMA表看到第14,“information_schema和数据字典一体化” Atomic DDL。看到第13.1.1,“原子数据定义语句的支持” 重要 数据字典功能的服务器需要一些运作上的差异相比,...