Consultas y Transformación Avanzada de Datos
Diseño y Optimización Avanzada de Bases de Datos con SQL y MySQL
Construcción de Base de Datos en MySQL: Terminal, Tablas y Datos Simulados
Transformación de Datos con SQL: De Consultas Simples a Superqueries
Columnas Generadas en SQL
Expresiones Regulares y Slugs en SQL y MySQL: Casos de Uso Reales
Automatización, Reutilización y Eficiencia en Consultas
Vistas y Tablas Virtuales en SQL
Consultas Anidadas y Vistas Materializadas
Triggers y Vistas Materializadas en MySQL (Kinda)
Automatización de Bases de Datos con Triggers en MySQL
Llaves Primarias e Índices
Trabajo con Datos Avanzados (JSON)
Uso de JSON en MySQL: Almacenamiento Eficiente de Datos Estructurados
Búsquedas Avanzadas con JSON en MySQL: Indexación y Optimización
Joins en SQL: Conecta Tablas y Mejora tus Consultas
Motores de Almacenamiento y Encodings
Gestión de Usuarios y Permisos en SQL
Gestión Avanzada y Análisis de Bases de Datos
Information Schema en MySQL: Análisis Interno de tu Base de Datos
Mysqldump
Domina las Migrations: Evoluciona y Gestiona tu Base de Datos con Eficiencia
Optimiza tus Decisiones con Metabase
You don't have access to this class
Keep learning! Join and start boosting your career
Database management goes beyond simple SQL queries. Knowing the internal tools that MySQL offers us to monitor and understand our own databases is fundamental for any developer or system administrator. This time, we will explore one of the most valuable but less known databases: Information Schema, which allows us to obtain detailed information about our tables, indexes and general performance.
Information Schema is a special database that MySQL automatically provides to all users, even those with limited permissions. This database contains tables with metadata about all other databases on the server, their tables, columns, indexes and much more.
Unlike the MySQL database (which stores system configurations), Information Schema focuses on storing hard data about our data structures. This information is extremely valuable for monitoring the growth of our databases, optimizing queries and better understanding our data model.
To access it we simply use:
USE information_schema;SHOW TABLES;
Among all the tables available in Information Schema, one of the most useful is TABLES
. This table contains detailed information about all tables in all databases on the server:
SELECT *FROM information_schema.TABLESWHERE TABLE_SCHEMA = 'platzi_sql';
This query shows us information such as:
We can create a custom view that shows us the most relevant information about our tables, including byte conversions to more readable units:
CREATE VIEW db_status ASSELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, TABLE_ROWS, DATA_LENGTH / (1024 * 1024) AS DATA_LENGTH_IN_MEGABYTES,
AVERAGE_ROW_LENGTH / 1024 AS AVERAGE_ROW_LENGTH_IN_KILOBYTES, INDEX_LENGTH / (1024 * 1024) AS INDEX_LENGTH_IN_MEGABYTESFROM information_schema.TABLESWHERE TABLE_SCHEMA = 'platzi_sql';
This view allows us to quickly query the status of our database:
SELECT * FROM db_status;
By analyzing the results of our db_status
view, we can obtain valuable insights about our database:
Relationship between data and indexes: In the example shown, the clients
table has a data size of about 20 MB, while its indexes occupy about 5 MB. This means that the indexes represent approximately 25% of the total size.
Table growth: Monitoring the growth of tables over time helps us identify whether our catalog tables are behaving as we expect or if they are growing faster than expected.
Data volume: Seeing that we have 96,000 customers in a week of operation can be an important indicator of business performance.
Creating a view like db_status
has significant operational benefits:
Although the TABLES
table is extremely useful, Information Schema contains many other tables with valuable information:
COLUMNS
: Information about all columns in all tables.STATISTICS
: Data about indexesKEY_COLUMN_USAGE
: Information about key restrictionsINNODB_METRICS
: InnoDB engine specific metricsWhile these additional tables may not be necessary on a day-to-day basis, knowing their existence is valuable for when you need to troubleshoot issues specific to your installation, model or business.
MySQL's transparency in providing access to its internal statistics is one of its great strengths. Take advantage of these tools to better understand your data and optimize your system.
Information Schema is just the beginning of a more advanced set of tools for database management. In upcoming sessions, we will explore equally important topics such as backups, migrations and data visualization with tools like Metabase. Don't miss them!
Contributions 0
Questions 0
Want to see more contributions, questions and answers from the community?