2013-03-30 3 views
11

다음 쿼리로 MySQL 테이블의 크기를 GB로 계산하면 끝납니다. TABLE_SCHEMA = 'DB'및 TABLE_NAME = 'TABLENAME'GB에서 MySQL 행 크기를 얻는 방법

그것이 가능한 얻는 것입니다 INFORMATION_SCHEMA.TABLES FROM

SELECT (data_length보다 index_length +)/전력 (1024,3) tablesize_gb GB 단위의 MySQL 행 크기.

또는 GB의 테이블에 대한 평균 행 크기를 얻는 방법.

+0

그룹과 이유는 여기에있다. – nneonneo

+0

@nneonneo 위의 쿼리에서 테이블 크기를 얻었지만 행 크기를 가져와야합니다. – Parthi04

+0

행 수로 나누시겠습니까? – nneonneo

답변

11

평균 행 길이 (오버 헤드 포함)를 얻으려면 information_schema.tables에 AVG_ROW_LENGTH 열을 사용하십시오.

알고있는 한, MySQL의 특정 단일 행의 정확한 실제 크기를 계산할 방법이 없습니다.

-3

테이블의 크기는 우리가 이런 일을 사용할 수 있습니다 찾으려면 ..

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 
     WHERE table_name like "%table-name%" 

우리는 안녕이 트릭을 할 수있는이

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

이 질문은 특히 가장 큰 테이블이 아니라 가장 큰 행 크기를 찾는 것에 관한 것입니다. – coderintherye

5

같은 것을 사용할 수 있습니다 MYSQL 데이터베이스에서 가장 큰 테이블을 찾기 비슷한 문제가있어 어떤 유형의 행이 가장 많은 공간을 차지하는지 알아야했습니다. 즉으로 ... 그것을 할 수있는 합리적인 방법처럼 보인다

SELECT groupval, (sum(length(somefield) + length(someotherfield))/1024)/1024 as "fields_size_mb" 
FROM table 
GROUP BY groupval 
ORDER BY fields_size_mb desc; 
-1
SELECT 
    table_name AS `Table`, 
    round(((data_length + index_length)/1024/1024), 2) as `Size in MB`, 
    round((AVG_ROW_LENGTH/1024), 2) as `Avg row size in KB` 
FROM information_schema.TABLES WHERE table_schema = 'your_db_name' 
ORDER BY `Size in MB` DESC