MySQL元数据

概述

元数据是关于数据的数据。MySQL通过系统数据库和信息模式表提供广泛的元数据,允许您查询数据库结构、表定义、索引等。

元数据源

information_schema:关于所有数据库的元数据 users / mysql:包含权限/用户的系统数据库 performance_schema:性能指标 sys:performance_schema的视图 SHOW命令:直接显示元数据

information_schema数据库

概述

-- 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

数据库元数据

-- List all databases

-- Database character sets

-- Database sizes

表元数据

-- List tables in current database

-- Filter by engine

-- Filter by table type

列元数据

-- Get table columns

-- Find nullable columns

-- Find auto increment columns

索引元数据

-- List indexes

-- Index details

-- Unique indexes

SHOW命令

数据库SHOW命令

-- Show databases

-- Show current database

-- Show character sets

-- Show collations

-- Show engines

表SHOW命令

-- Show tables

-- Show table structure

-- Show create statement

-- Show table status

索引SHOW命令

-- Show indexes

-- Show index details

其他SHOW命令

-- Show users

-- Show privileges

-- Show processes

-- Show variables

-- Show status

-- Show engines

MySQL系统数据库

mysql数据库

-- Use mysql database

-- User information

-- Database privileges

-- Table privileges

-- Column privileges

-- Proxies

用户元数据

-- List all users

-- User with all hosts

-- User privileges

-- Password hashes

性能元数据

performance_schema数据库

-- Use performance_schema

-- Show available instruments

-- Enable instruments

-- Show consumers

性能查询

-- Wait events

-- Statement performance

-- Table I/O

sys数据库

-- Use sys database (MySQL 5.7+)

-- User statistics

-- Table statistics

-- Wait analysis

-- Memory usage

元数据查询

搜索表

-- Find tables with specific column

-- Find tables without primary key

-- Find tables with specific engine

搜索列

-- Find all columns named 'email'

-- Find all VARCHAR columns

-- Find all datetime columns

搜索约束

-- Find foreign keys

-- Find unique constraints

元数据函数

数据库信息函数

-- Current database

-- Current user

-- Connection ID

-- Last insert ID

表信息函数

-- Row count

-- Auto increment value

-- Check table existence

实用示例

数据库文档

-- Generate table documentation

模式比较

-- Compare tables between databases

未使用的索引

-- Find potentially unused indexes

外键报告

-- Generate foreign key documentation

小结

MySQL元数据提供:

数据库信息:名称、大小、引擎 表信息:列、行、索引 列信息:类型、默认值、约束 索引信息:键、基数、唯一性 O / 性能数据:查询、等待、I/O Privilege Data**: Grants, roles / 用户/权限数据:授权、角色

使用元数据进行数据库管理、文档、优化和监控。


上一个:复制表

下一个:序列