1、查詢整個mysql數(shù)據(jù)庫,整個庫的大小;單位轉(zhuǎn)換為MB。
林周網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),林周網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為林周成百上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請找那個售后服務(wù)好的林周做網(wǎng)站的公司定做!
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data? from information_schema.TABLES
2、查詢mysql數(shù)據(jù)庫,某個庫的大??;
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data
from information_schema.TABLES
where table_schema = 'testdb'
3、查看庫中某個表的大??;
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data
from information_schema.TABLES
where table_schema = 'testdb'
and table_name = 'test_a';
4、查看mysql庫中,test開頭的表,所有存儲大?。?/p>
select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data
from information_schema.TABLES
where table_schema = 'testdb'
and table_name like 'test%';
--1、查看表空間的名稱及大小
select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
--2、查看表空間物理文件的名稱及大小
select tablespace_name, file_id, file_name,
round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
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)
如題,找到MySQL中的information_schema表,這張表記錄了所有數(shù)據(jù)庫中表的信息,主要字段含義如下:
TABLE_SCHEMA : 數(shù)據(jù)庫名
TABLE_NAME:表名
ENGINE:所使用的存儲引擎
TABLES_ROWS:記錄數(shù)
DATA_LENGTH:數(shù)據(jù)大小
INDEX_LENGTH:索引大小
如果需要查詢所有數(shù)據(jù)庫占用空間大小只需要執(zhí)行SQL命令:
mysql use information_schema
Database changed
mysql SELECT sum(DATA_LENGTH+INDEX_LENGTH) FROM TABLES;
+-------------------------------+
| sum(DATA_LENGTH+INDEX_LENGTH) |
+-------------------------------+
| 683993 |
+-------------------------------+
1 row in set (0.00 sec)
大小是字節(jié)數(shù) 如果想修改為KB可以執(zhí)行:
SELECT sum(DATA_LENGTH+INDEX_LENGTH)/1024 FROM TABLES;
如果修改為MB應(yīng)該也沒問題了吧
如果需要查詢一個數(shù)據(jù)庫所有表的大小可以執(zhí)行:
SELECT sum(DATA_LENGTH+INDEX_LENGTH) FROM TABLES WHERE TABLE_SCHEMA='數(shù)據(jù)庫名'
查詢所有數(shù)據(jù)庫占用磁盤空間大小的SQL語句:
復(fù)制代碼
代碼如下:
select
TABLE_SCHEMA,
concat(truncate(sum(data_length)/1024/1024,2),'
MB')
as
data_size,
concat(truncate(sum(index_length)/1024/1024,2),'MB')
as
index_size
from
information_schema.tables
group
by
TABLE_SCHEMA
order
by
data_length
desc;
查詢單個庫中所有表磁盤占用大小的SQL語句:
復(fù)制代碼
代碼如下:
select
TABLE_NAME,
concat(truncate(data_length/1024/1024,2),'
MB')
as
data_size,
concat(truncate(index_length/1024/1024,2),'
MB')
as
index_size
from
information_schema.tables
where
TABLE_SCHEMA
=
'TestDB'
group
by
TABLE_NAME
order
by
data_length
desc;
以上語句測試有效,注意替換以上的TestDB為數(shù)據(jù)庫名
1、進去指定schema 數(shù)據(jù)庫(存放了其他的數(shù)據(jù)庫的信息)\x0d\x0ause information_schema\x0d\x0a2、查詢所有數(shù)據(jù)的大小\x0d\x0aselect concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES\x0d\x0a3、查看指定數(shù)據(jù)庫的大小\x0d\x0a比如說 數(shù)據(jù)庫apoyl\x0d\x0aselect concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='apoyl';\x0d\x0a4、查看指定數(shù)據(jù)庫的表的大小\x0d\x0a比如說 數(shù)據(jù)庫apoyl 中apoyl_test表\x0d\x0aselect concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='apoyl' and table_name='apoyl_test';\x0d\x0a整完了,有興趣的可以試哈哦!挺使用哈\x0d\x0a網(wǎng)站找的,都是正解