MySql DB/테이블 관리용 쿼리

1. 테이블별 사이즈 확인 (쿼리 시점에 정확한 사이즈는 아니지만, 참고할 만한 데이터임) [출처]

SELECT 
    table_name,
    table_rows,
    round(data_length/(1024*1024),2) as 'DATA_SIZE(MB)',
    round(index_length/(1024*1024),2) as 'INDEX_SIZE(MB)'
FROM information_schema.TABLES
where table_schema = '데이터베이스이름'
GROUP BY table_name 
ORDER BY data_length DESC 
LIMIT 10;

2. Database 별 사이즈 확인 (쿼리 시점에 정확한 사이즈는 아니지만, 참고할 만한 데이터임)[출처]

SELECT
count(*) NUM_OF_TABLE,
table_schema,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
GROUP BY table_schema
ORDER BY sum(data_length+index_length) DESC LIMIT 10;

--=--
참고로 적자면, innoDB를 사용할 경우 크기 계산은 '대략' 적인 계산이 된다.


--=--
# 테이블 정보 보기
SHOW TABLE STATUS;
SHOW TABLE STATUS LIKE '{테이블명}';
따지면..  information_schema.TABLES 의 용약판이겠지만, 일반적으로 사용되는 상태 확인 쿼리이다.
댓글
  • No Nickname
    No Comment
  • 권한이 없습니다.
    {{m_row.m_nick}}
    -
목록형 📷 갤러리형
제목
[기본형] HTML (with 부트스트랩5.3 , jquery 3.7, vue.js)
유용한 리눅스(LINUX) 명령어
[공지] 기술 게시판
4.28
4.29
4.30
5.1
5.2
5.3
5.4
5.5
5.6
5.7
5.8
5.9
5.10
5.11
5.12
5.13
5.14
5.15
5.16
5.17
5.18
5.19
5.20
5.21
5.22
5.23
5.24
5.25
5.26
5.27
5.28
5.29
5.30
5.31
6.1