MySQL元数据
概述
元数据是关于数据的数据。MySQL通过系统数据库和信息模式表提供广泛的元数据,允许您查询数据库结构、表定义、索引等。
元数据源
information_schema:关于所有数据库的元数据 users / mysql:包含权限/用户的系统数据库 performance_schema:性能指标 sys:performance_schema的视图 SHOW命令:直接显示元数据
information_schema数据库
概述
sql
-- Access information_schema
-- List all information_schema tables
-- Key information_schema tables
-- SCHEMATA: Database information
-- TABLES: Table information
-- COLUMNS: Column information
-- KEY_COLUMN_USAGE: Key usage
-- STATISTICS: Index information
-- USER_PRIVILEGES: User privileges
-- TABLE_CONSTRAINTS: Constraints数据库元数据
sql
-- List all databases
-- Database character sets
-- Database sizes表元数据
sql
-- List tables in current database
-- Filter by engine
-- Filter by table type列元数据
sql
-- Get table columns
-- Find nullable columns
-- Find auto increment columns索引元数据
sql
-- List indexes
-- Index details
-- Unique indexesSHOW命令
数据库SHOW命令
sql
-- Show databases
-- Show current database
-- Show character sets
-- Show collations
-- Show engines表SHOW命令
sql
-- Show tables
-- Show table structure
-- Show create statement
-- Show table status索引SHOW命令
sql
-- Show indexes
-- Show index details其他SHOW命令
sql
-- Show users
-- Show privileges
-- Show processes
-- Show variables
-- Show status
-- Show enginesMySQL系统数据库
mysql数据库
sql
-- Use mysql database
-- User information
-- Database privileges
-- Table privileges
-- Column privileges
-- Proxies用户元数据
sql
-- List all users
-- User with all hosts
-- User privileges
-- Password hashes性能元数据
performance_schema数据库
sql
-- Use performance_schema
-- Show available instruments
-- Enable instruments
-- Show consumers性能查询
sql
-- Wait events
-- Statement performance
-- Table I/Osys数据库
sql
-- Use sys database (MySQL 5.7+)
-- User statistics
-- Table statistics
-- Wait analysis
-- Memory usage元数据查询
搜索表
sql
-- Find tables with specific column
-- Find tables without primary key
-- Find tables with specific engine搜索列
sql
-- Find all columns named 'email'
-- Find all VARCHAR columns
-- Find all datetime columns搜索约束
sql
-- Find foreign keys
-- Find unique constraints元数据函数
数据库信息函数
sql
-- Current database
-- Current user
-- Connection ID
-- Last insert ID表信息函数
sql
-- Row count
-- Auto increment value
-- Check table existence实用示例
数据库文档
sql
-- Generate table documentation模式比较
sql
-- Compare tables between databases未使用的索引
sql
-- Find potentially unused indexes外键报告
sql
-- Generate foreign key documentation小结
MySQL元数据提供:
数据库信息:名称、大小、引擎 表信息:列、行、索引 列信息:类型、默认值、约束 索引信息:键、基数、唯一性 O / 性能数据:查询、等待、I/O Privilege Data**: Grants, roles / 用户/权限数据:授权、角色
使用元数据进行数据库管理、文档、优化和监控。
上一个:复制表
下一个:序列