Consultas útiles para MySql

0 - , - 14/05/2008 14:51:57

En MySQL Performance blog he encontrado algunas consultas MySQL muy útiles a la hora de controlar el tamaño y optimizar nuestras bases de datos. Por ejemplo, la siguiente consulta nos devuelve el número total de tablas, filas, el tamaño de nuestros datos e índices,...

SELECT count(*) TABLES,
CONCAT(ROUND(sum(table_rows)/1000000,2),'M') rows,
CONCAT(ROUND(sum(data_length)/(1024*1024*1024),2),'G') DATA,
CONCAT(ROUND(sum(index_length)/(1024*1024*1024),2),'G') idx,
CONCAT(ROUND(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
ROUND(sum(index_length)/sum(data_length),2) idxfrac
FROM information_schema.TABLES;

La siguiente nos muestra las 10 tablas más grandes de nuestra base de datos

SELECT
CONCAT(table_schema,'.',table_name),
CONCAT(ROUND(table_rows/1000000,2),'M') rows,
CONCAT(ROUND(data_length/(1024*1024*1024),2),'G') DATA,
CONCAT(ROUND(index_length/(1024*1024*1024),2),'G') idx,
CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),2),'G') total_size,
ROUND(index_length/data_length,2) idxfrac FROM information_schema.TABLES
ORDER BY data_length+index_length DESC LIMIT 10;

Researching your MySql table sizes » »

Deja tu comentario

  • El comentario debe estar relacionado con el contenido de la entrada.
  • Comentarios ofensivos, con spam o con lenguaje inapropiado serán eliminados.

captcha