Python/Python Programming

[Python] Check the capacity of the mariadb table using pymysql

Pydole 2020. 2. 6. 11:21

 

MariaDB Table Space Show Query

 

 

 SELECT  table_schema, SUM(data_length+index_length) as Byte 
 FROM information_schema.tables 
 GROUP BY table_schema 
 ORDER BY Byte DESC

 

 

 

Using pymysql

 

import pymysql

conn = pymysql.connect(host=' ', port= , user=' ', password=' ', db=' ',charset='utf8')
c = conn.cursor()
sql = '''
SELECT  table_schema, SUM(data_length+index_length) as Byte
FROM information_schema.tables
GROUP BY table_schema
ORDER BY Byte DESC'''
c.execute(sql)

rows = c.fetchall()

for row in rows:
    print(row[0],row[1])
    
 ---------------------------------------------------------------------------------------
 

xxxxx 38584320
mysql 756143
information_schema 180224
performance_schema 0

 


파이썬 pymysql 모듈을 이용한 테이블스페이스 용량 확인.