資料庫 mysql 庫表以及索引大小查詢

2021-10-14 13:14:58 字數 1870 閱讀 3292

資料常見的一些引數,比如庫大小,表大小,索引大小等指標有助於我們了解資料庫,更好的使用資料庫及優化。

-- 資料庫 mysql 庫表以及索引大小查詢

-- 檢視指定庫的大小

select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='testschema';

-- 檢視指定庫的指定表的大小

select concat(round(sum(data_length/1024/1024),2),'mb') as data from tables where table_schema='testschema' and table_name='t_syt_keyword_off_rep';

-- 檢視指定庫的索引大小

select concat(round(sum(index_length)/(1024*1024), 2), ' mb') as 'total index size' from tables where table_schema = 'testschema';

-- 檢視指定庫的指定表的索引大小

select concat(round(sum(index_length)/(1024*1024), 2), ' mb') as 'total index size' from tables where table_schema = 'testschema' and table_name='tab_user';

-- 1.檢視指定庫資料和索引大小總和

select concat(round(sum((data_length+index_length)/1024/1024),2),'mb') as total_data from information_schema.tables where table_schema = 'testschema';

-- 2.檢視所有庫資料和索引大小總和

select concat(round(sum((data_length+index_length)/1024/1024),2),'mb') as total_data from information_schema.tables;

-- 3.檢視指定資料庫的某個表

select concat(round(sum((data_length+index_length)/1024/1024),2),'mb') as data from tables where table_schema='testschema' and table_name='tab_user';

-- 4.查詢乙個庫中每個表的資料大小,索引大小和總大小

select

concat(a.table_schema,'.',a.table_name),

concat(round(table_rows/1000,4),'kb') as 'number of rows',

concat(round(data_length/(1024*1024),4),',') as 'data_size',

concat(round(index_length/(1024*1024),4),'m') as 'index_size',

concat(round((data_length+index_length)/(1024*1024),4),'m') as'total'

from

information_schema. tables a

where

a.table_schema = 'testschema';

建立資料庫 表以及索引

這樣做就可以建立乙個資料庫 create database 資料庫名稱這樣做就可以建立乙個資料庫中的表 create table 表名稱 列名稱1 資料型別,列名稱2 資料型別,本例演示如何建立名為 person 的表,有四個列。列名是 lastname firstname address 以及 a...

資料庫mysql索引 資料庫 mysql索引

mysql 索引 mysql索引的建立對於mysql的高效執行是很重要的,索引可以大大提高mysql的檢索速度。打個比方,如果合理的設計且使用索引的mysql是一輛蘭博基尼的話,那麼沒有設計和使用索引的mysql就是乙個人力三輪車。索引分單列索引和組合索引。單列索引,即乙個索引只包含單個列,乙個表可...

SQL 撤銷索引 表以及資料庫

通過使用 drop 語句,可以輕鬆地刪除索引 表和資料庫。sql drop index 語句 我們可以使用 drop index 命令刪除 中的索引。用於 microsoft sqljet 以及 microsoft access 的語法 drop index index name on table ...