简介:information_schema 是 MySQL 数据库中内置的一个系统数据库(信息数据库),它的作用主要是存储关于整个MySQL实例当中所有数据库、数据表、列、索引、约束、存储过程、函数、触发器等各种元数据信息。我们日常使用它可以很方便查询和分析数据库的结构和数据库的一些统计信息。information_schema数据库只有MySQL5.0版本以上会自带。
注意:information_schema 中的数据是只读的,不允许对其进行修改。
如果本文章对你有帮助的话,请点赞收藏加关注吧,后面还会更新更多实用干货
目录:
1.查数据库名
select schema_name from information_schema.schemata;
//schema_name字段里面储存了所有数据库名
//information_schema.schemata信息数据库中的schemata表
2.查询某个数据库中的表名
select table_name from information_schema.tables where table_schema='security';
//table_name字段里面储存了整个数据库系统中所有表名
//information_schema.tables表里有table_name字段
//table_schema可以理解为那个数据库
3 .查询某个数据库下某个表的列名
select column_name from information_schema.columns where table_schema='security' and table_name='users';
//column_name字段里面储存了整个数据库系统的所有字段名
//information_schema.columns表里储存了column_name字段
//table_schema可以理解为那个数据库
//table_name可以理解为哪个表