mysql表類型查詢示例詳解
普通表
SELECT table_schema AS database_name, table_name FROM information_schema.tables WHERE table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys') AND table_type = 'BASE TABLE' AND table_name NOT IN ( SELECT DISTINCT table_name FROM information_schema.partitions WHERE partition_name IS NOT NULL ) ORDER BY table_schema, table_name;
分區(qū)表
SELECT p.table_schema AS database_name, p.table_name, GROUP_CONCAT(p.partition_name ORDER BY p.partition_ordinal_position) AS partitions, p.partition_method, p.partition_expression FROM information_schema.partitions p WHERE p.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys') AND p.partition_name IS NOT NULL GROUP BY p.table_schema, p.table_name, p.partition_method, p.partition_expression ORDER BY p.table_schema, p.table_name;
區(qū)分表
SELECT t.table_schema AS database_name, t.table_name, CASE WHEN p.table_name IS NULL THEN '普通表' ELSE '分區(qū)表' END AS table_type, p.partition_method, p.partition_expression FROM information_schema.tables t LEFT JOIN ( SELECT DISTINCT table_schema, table_name, partition_method, partition_expression FROM information_schema.partitions WHERE partition_name IS NOT NULL ) p ON t.table_schema = p.table_schema AND t.table_name = p.table_name WHERE t.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys') AND t.table_type = 'BASE TABLE' ORDER BY t.table_schema, t.table_name;
查出數(shù)據(jù)量
SELECT t.table_schema AS '數(shù)據(jù)庫名', t.table_name AS '表名', CASE WHEN p.table_name IS NULL THEN '普通表' ELSE CONCAT('分區(qū)表(', p.partition_method, ')') END AS '表類型', t.table_rows AS '數(shù)據(jù)行數(shù)(估算)', CONCAT(ROUND(t.data_length / (1024 * 1024), 2), ' MB') AS '數(shù)據(jù)大小', CONCAT(ROUND(t.index_length / (1024 * 1024), 2), ' MB') AS '索引大小', CONCAT(ROUND((t.data_length + t.index_length) / (1024 * 1024), 2), ' MB') AS '總大小', p.partition_expression AS '分區(qū)鍵' FROM information_schema.tables t LEFT JOIN ( SELECT DISTINCT table_schema, table_name, partition_method, partition_expression FROM information_schema.partitions WHERE partition_name IS NOT NULL ) p ON t.table_schema = p.table_schema AND t.table_name = p.table_name WHERE t.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys') AND t.table_type = 'BASE TABLE' ORDER BY t.table_schema, CASE WHEN p.table_name IS NULL THEN 0 ELSE 1 END, -- 普通表在前 t.table_name; SELECT t.table_schema AS '數(shù)據(jù)庫', t.table_name AS '表名', CASE WHEN p.partition_method IS NULL THEN '普通表' ELSE CONCAT('分區(qū)表(', p.partition_method, ')') END AS '表類型', t.table_rows AS '估算行數(shù)', CONCAT(ROUND(t.data_length/1024/1024, 2), ' MB') AS '數(shù)據(jù)大小', p.partition_expression AS '分區(qū)鍵' FROM information_schema.tables t LEFT JOIN ( SELECT table_schema, table_name, partition_method, partition_expression FROM information_schema.partitions WHERE partition_name IS NOT NULL GROUP BY table_schema, table_name, partition_method, partition_expression ) p ON t.table_schema = p.table_schema AND t.table_name = p.table_name WHERE t.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys') AND t.table_type = 'BASE TABLE' ORDER BY t.table_schema, t.table_name;
查出表行數(shù)
SELECT t.table_schema AS '數(shù)據(jù)庫', t.table_name AS '表名', CASE WHEN p.partition_method IS NULL THEN '普通表' ELSE CONCAT('分區(qū)表(', p.partition_method, ')') END AS '表類型', t.table_rows AS '估算行數(shù)', p.partition_expression AS '分區(qū)鍵' FROM information_schema.tables t LEFT JOIN ( SELECT DISTINCT table_schema, table_name, partition_method, partition_expression FROM information_schema.partitions WHERE partition_name IS NOT NULL ) p ON t.table_schema = p.table_schema AND t.table_name = p.table_name WHERE t.table_schema NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys') AND t.table_type = 'BASE TABLE' ORDER BY t.table_schema, t.table_name;
到此這篇關(guān)于mysql表類型查詢的文章就介紹到這了,更多相關(guān)mysql表類型查詢內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
RedHat6.5/CentOS6.5安裝Mysql5.7.20的教程詳解
這篇文章主要介紹了RedHat6.5/CentOS6.5安裝Mysql5.7.20的教程詳解,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-11-11Windows10下mysql 8.0.16 安裝配置方法圖文教程
這篇文章主要為大家詳細(xì)介紹了Windows10下mysql 8.0.16 安裝配置方法圖文教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-05-05MySql?字符集不同導(dǎo)致?left?join?慢查詢的問題解決
當(dāng)兩個表的字符集不一樣,在使用字符型字段進(jìn)行表連接查詢時,就需要特別注意下查詢耗時是否符合預(yù)期,本文主要介紹了MySql?字符集不同導(dǎo)致?left?join?慢查詢的問題解決,感興趣的可以了解一下2024-05-05解決mysql報錯:Data?source?rejected?establishment?of?connect
這篇文章主要給大家介紹了關(guān)于如何解決mysql報錯:Data?source?rejected?establishment?of?connection,?message?from?server:?\"Too?many?connectio的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02MYSQL使用Union將兩張表的數(shù)據(jù)合并顯示
使用union操作符會將多張表中相同的數(shù)據(jù)取值一次,如果想將表1和表2中的值完整的顯示出來,可以使用union all,今天通過本文給大家分享MYSQL使用Union將兩張表的數(shù)據(jù)合并顯示功能,需要的朋友參考下吧2021-08-08詳解MySQL的主從復(fù)制、讀寫分離、備份恢復(fù)
本篇文章主要對MySQL的主從復(fù)制、讀寫分離、備份恢復(fù)進(jìn)行詳細(xì)全面的講解,具有很好的參考價值,需要的朋友一起來看下吧2016-12-12Mysql外鍵設(shè)置中的CASCADE、NO ACTION、RESTRICT、SET NULL
本文主要介紹了Mysql外鍵設(shè)置中的CASCADE、NO ACTION、RESTRICT、SET NULL,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07