在MySQL
Workbench中运行以下SQL语句:
—
以GB为单位
SELECT
CONCAT(ROUND(SUM(index_length)/(1024*1024*1024),
6),
‘
GB’)
AS
‘Total
Index
Size’
FROM
information_schema.TABLES
WHERE
table_schema
LIKE
‘database’
—
以MB为单位
SELECT
CONCAT(ROUND(SUM(index_length)/(1024*1024),
6),
‘
MB’)
AS
‘Total
Index
Size’
FROM
information_schema.TABLES
WHERE
table_schema
LIKE
‘database’
其中,database是待查看数据库的名称,例如:lsqdb%。运行结果如下图所示:
2.
查看数据库的数据空间大小
在MySQL
Workbench中运行以下SQL语句:
—
以GB为单位
SELECT
CONCAT(ROUND(SUM(data_length)/(1024*1024*1024),
6),
‘
GB’)
AS
‘Total
Data
Size’
FROM
information_schema.TABLES
WHERE
table_schema
LIKE
‘database’
—
以MB为单位
SELECT
CONCAT(ROUND(SUM(data_length)/(1024*1024),
6),
‘
MB’)
AS
‘Total
Data
Size’
FROM
information_schema.TABLES
WHERE
table_schema
LIKE
‘database’
其中,database是待查看数据库的名称,例如:lsqdb%。运行结果如下图所示:
3.
查看数据库中所有表的信息
在MySQL
Workbench中运行以下SQL语句,查看数据库中所有表的表名、表行数、数据空间大小、索引空间大小和总大小:
SELECT
CONCAT(table_schema,’.’,table_name)
AS
‘Table
Name’,
table_rows
AS
‘Number
of
Rows’,
CONCAT(ROUND(data_length/(1024*1024),6),’
MB’)
AS
‘Data
Size’,
CONCAT(ROUND(index_length/(1024*1024),6),’
MB’)
AS
‘Index
Size’,
CONCAT(ROUND((data_length+index_length)/(1024*1024),6),’
MB’)
AS’Total
Size’
FROM
information_schema.TABLES
WHERE
table_schema
LIKE
‘database’
其中,database是待查看数据库的名称,例如:lsqdb%。
mysql>show databases+--------------------+
| Database |
+--------------------+
| information_schema |
| hnmcc |
| hnmcc_ecp |
| hnmcc_push |
| hnmcc_sso |
| mysql |
| percona|
| performance_schema |
| test |
+--------------------+
9 rows in set (0.00 sec)
// 使用mysql自带管理表information_schema.
mysql>use information_schema;
mysql>select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='hnmcc' and table_name='l_log_20160102'
+-----------+
| data |
+-----------+
| 4803.00MB |
+-----------+
1 row in set (0.00 sec)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)