从MySQL 5开始, 你可以看到多了一个系统数据库information_schema . information_schema 存贮了其他所有数据库的信息。让我们来看看几个使用这个数据库的例子:
<!--more-->
1. 取得关于 information_schema的基本信息
information_schema是一个虚拟数据库,并不物理存在,在select的时候,从其他数据库获取相应的信息。
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bugs |
| mysql |
| sugarcrm |
+--------------------+
4 rows in set (0.00 sec)
以下是information_schema数据库中的表.
mysql> use information_schema;
mysql> show tables;
+---------------------------------------+
| Tables_in_information_schema |
+---------------------------------------+
| CHARACTER_SETS |
| COLLATIONS |
| COLLATION_CHARACTER_SET_APPLICABILITY |
| COLUMNS |
| COLUMN_PRIVILEGES |
| KEY_COLUMN_USAGE |
| PROFILING |
| ROUTINES |
| SCHEMATA |
| SCHEMA_PRIVILEGES |
| STATISTICS |
| TABLES |
| TABLE_CONSTRAINTS |
| TABLE_PRIVILEGES |
| TRIGGERS |
| USER_PRIVILEGES |
| VIEWS |
+---------------------------------------+
17 rows in set (0.00 sec)
2. 查询表中数据超过1000行的表
以下的语句可以查出超过1000行数据的表
mysql> select concat(table_schema,'.',table_name) as table_name,table_rows
-> from information_schema.tables where table_rows > 1000
-> order by table_rows desc;
+----------------------------------+------------+
| table_name | table_rows |
+----------------------------------+------------+
| bugs.series_data | 52778 |
| bugs.bugs_activity | 26436 |
| bugs.longdescs | 21473 |
| bugs.email_setting | 5370 |
| bugs.attachments | 4714 |
| bugs.attach_data | 4651 |
| bugs.cc | 4031 |
| bugs.bugs | 2190 |
| bugs.namedqueries_link_in_footer | 1228 |
+----------------------------------+------------+
9 rows in set (0.04 sec)
3. 查询所有没有主键的表
This example gives a list of all the tables without primary key.
SELECT CONCAT(t.table_name,".",t.table_schema) 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';
4. 实现表的历史数据information_schema
Putting the MySQL information_schema to Use article implements a history database using the information schema. The first half of this article describes the requirements for the history database, and a generic design to implement it. The second half describes the stepwise construction of code-generator that creates the SQL to construct and load the history database. The code-generator is driven by the information schema and some features of the information schema are discussed in detail.
5. 查询5个嘴大表
mysql> SELECT concat(table_schema,'.',table_name) table_name,
-> concat(round(data_length/(1024*1024),2),'M') data_length
-> FROM information_schema.TABLES
-> ORDER BY data_length DESC LIMIT 5;
+--------------------+-------------+
| table_name | data_length |
+--------------------+-------------+
| bugs.attach_data | 706.89M |
| bugs.longdescs | 3.45M |
| bugs.bugs_activity | 1.45M |
| bugs.series_data | 0.75M |
| bugs.attachments | 0.51M |
+--------------------+-------------+
5 rows in set (0.05 sec)
分享到:
相关推荐
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注入中的应用思路。
新装的mysql里面有两个数据库:information_schema 和 mysql 。他们是干么用的?可以删除么?当然是不可以删除的。1.information schema 是mysql系统用的所有字典信息,包括数据库系统有什么库,有什么表,有什么...
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
通过Linux指令直接获取数据库和数据表信息: mysql -uroot -pxxxx -D information_schem
mySQL索引查看 select * from information_schema.statistics where table_schema='数据库名称' and table_name = '表名称'
Mysql_set_charset('gbk','$conn') Left ?Id=1 and 1=left(database(),1)=5--+ Substr ?Id=1 and ascii(substr(database(),1,1))>90--+ Regexp ?id=1' and 1=(select 1 from information_schema.tables...
选择*从城市选择*来自国家从国家/地区语言中选择* 您还可以像检查数据库从information_schema.tables中选择* 从information_schema.columns中选择*MySQL的heroku world.sql已导入。 世界数据库下面有3个表城市国家...
23. INFORMATION_SCHEMA信息数据库 24. 精度数学 25. API和库 26. 连接器 27. 扩展MySQL A. 问题和常见错误 B. 错误代码和消息 C. 感谢 D. MySQL变更史 E. 移植到其他系统 F. 环境变量 G. 正则表达式 H. Limits in ...
代码如下: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...
主要介绍了MySQL 8.0统计信息不准确的原因,帮助大家更好的理解和学习MySQL8.0的相关内容,感兴趣的朋友可以了解下
,,,,,,,,,, ,mysql版本,数据库服务器的版本 ,VERSION,,version,,select * from information_schema.GLOBAL_variables where VARIABLE_NAME in('VERSION');,,,,, ,端口,所运行的数据库服务器的端口号,REPORT_PORT,,...
1.查看mysql数据库大小SELECT sum(DATA_LENGTH)+sum(INDEX_LENGTH)FROM information_schema.TABLES where TABLE_SCHEMA=’数据库名’;得到的结果是以字节为单位,除1024为K,除1048576(=1024*1024)为M。 2.查看表的...
①.Mysql数据库的安装: 数据库的安装分为源码安装和rpm安装。 当然对于老手来说需要进行一些自定义的配置,那么当然源码安装的灵活性要高一些。 但是这种安装方式需要管理员自己处理好于系统的依赖关系。 而rpm安装...