数据库
首页 > 数据库> > MySQL数据量统计

MySQL数据量统计

作者:互联网

MySQL数据量统计

MySQL information_schema的常见使用

MySQL information_schema

information_schema数据库表说明:

统计数据库大小

select concat(round(sum(data_length/1024/1024),2),'MB') as data_length_MB,  
 concat(round(sum(index_length/1024/1024),2),'MB') as index_length_MB  
 from information_schema.tables where  
 table_schema='数据库名';

统计表大小

按照MB统计

select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,
concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,
concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables where TABLE_NAME='payment';

统计某个表的记录数

select table_schema,table_name,table_rows from tables where TABLE_SCHEMA = '数据库名' and (table_name='trade' or table_name='payment') order by table_rows desc;

查看会话连接信息

SELECT 
    THREAD_ID,
    name,
    type,
    PROCESSLIST_ID,
    PROCESSLIST_USER AS user,
    PROCESSLIST_HOST AS host,
    PROCESSLIST_DB AS db,
    PROCESSLIST_COMMAND AS cmd,
    PROCESSLIST_TIME AS time,
    PROCESSLIST_STATE AS state,
    PROCESSLIST_INFO AS info,
    CONNECTION_TYPE AS type,
    THREAD_OS_ID AS os_id
FROM
    performance_schema.threads
WHERE
    type = 'FOREGROUND'
ORDER BY THREAD_ID;

标签:1024,MB,mysql,信息,数据量,MySQL,PROCESSLIST,统计,schema
来源: https://www.cnblogs.com/DengSchoo/p/15175157.html