怎么样可以自己做网站,为知笔记发布WordPress,ico 众筹网站开发,做个营销型网站设计mysql 数据库空间统计 文章目录 mysql 数据库空间统计说明一、数据库存储代码二、查询某个数据库的所有表的 代码总结 说明
INFORMATION_SCHEMA Table Reference 表参考
information_schema是MySQL中的一个特殊数据库#xff0c;它存储了关于所有其他数据库的元数据信息。…mysql 数据库空间统计 文章目录 mysql 数据库空间统计说明一、数据库存储代码二、查询某个数据库的所有表的 代码总结 说明
INFORMATION_SCHEMA Table Reference 表参考
information_schema是MySQL中的一个特殊数据库它存储了关于所有其他数据库的元数据信息。 这些元数据包括数据库名、表名、列的数据类型、访问权限等。通过查询information_schema用户可以获取到关于数据库结构的详细信息这对于数据库管理和优化非常有帮助。例如可以通过查询information_schema来查看表的索引信息、视图定义、存储过程和函数的信息等。此外由于information_schema中的表都是只读的它们实际上可以被视为视图因此用户无法直接修改这些数据保证了元数据的完整性。 提示以下是本篇文章正文内容下面案例可供参考
一、数据库存储代码
请注意 如果启用了innodb_read_only系统变量ANALYZE TABLE可能会失败因为它无法更新使用InnoDB的数据字典中的统计表。对于更新键分布的ANALYZE TABLE操作即使操作更新表本身(例如如果它是一个MyISAM表)也可能发生失败。要获取更新的分布统计信息可以设置information_schema_stats_expiry0。 代码如下GB示例 select coalesce(table_schema, 合计) as table_schema,
concat(round(sum(data_length/1024/1024/1024),2),GB) as data_length_GB,
concat(round(sum(index_length/1024/1024/1024),2),GB) as index_length_GB ,
concat(round(sum(index_length/1024/1024/1024),2)round(sum(data_length/1024/1024/1024),2),GB) as tal_GB
from information_schema.tables t where table_TypeBASE TABLE
and table_schema not in (document,mysql,performance_schema,sys)
group by table_schema 代码如下MB示例 select coalesce(table_schema, 合计) as table_schema,
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 ,
concat(round(sum(index_length/1024/1024),2)round(sum(data_length/1024/1024),2),MB) as tal_MB
from information_schema.tables t where table_TypeBASE TABLE
and table_schema not in (document,mysql,performance_schema,sys)
group by table_schema WITH ROLLUP order by round(sum(data_length/1024/1024),2) desc 二、查询某个数据库的所有表的 代码
SELECTTABLE_NAME, ENGINE, VERSION, ROW_FORMAT, TABLE_ROWS, AVG_ROW_LENGTH,DATA_LENGTH, MAX_DATA_LENGTH, INDEX_LENGTH, DATA_FREE, AUTO_INCREMENT,CREATE_TIME, UPDATE_TIME, CHECK_TIME, TABLE_COLLATION, CHECKSUM,CREATE_OPTIONS, TABLE_COMMENTFROM INFORMATION_SCHEMA.TABLESWHERE table_schema db_name[AND table_name LIKE wild]SHOW TABLE STATUSFROM db_name[LIKE wild]The following statements are equivalent: SELECTTABLE_NAME, TABLE_TYPEFROM INFORMATION_SCHEMA.TABLESWHERE table_schema db_name[AND table_name LIKE wild]SHOW FULL TABLESFROM db_name[LIKE wild]具体可以查看 mysql 帮助
https://dev.mysql.com/doc/refman/8.0/en/information-schema-tables-table.html
总结
information_schema用于存储数据库元数据本文sql 主要是 MySQL系统库之information_schema的实现
查询数据库结构information_schema 可用于查询数据库、表、列、索引、外键、触发器等对象的结构信息。 权限管理可以使用 information_schema 查询用户和权限信息以确保正确的访问控制和权限设置。 性能优化information_schema 提供有关索引、表大小、表引擎等性能相关信息这对于性能优化很有帮助。 查询执行计划可以查询 information_schema 获取查询执行计划以了解查询如何被执行。 文章转载自: http://www.morning.krwzy.cn.gov.cn.krwzy.cn http://www.morning.wmmtl.cn.gov.cn.wmmtl.cn http://www.morning.tmnyj.cn.gov.cn.tmnyj.cn http://www.morning.prjns.cn.gov.cn.prjns.cn http://www.morning.rykn.cn.gov.cn.rykn.cn http://www.morning.lsjtq.cn.gov.cn.lsjtq.cn http://www.morning.xrrjb.cn.gov.cn.xrrjb.cn http://www.morning.weiwt.com.gov.cn.weiwt.com http://www.morning.qjxxc.cn.gov.cn.qjxxc.cn http://www.morning.rghkg.cn.gov.cn.rghkg.cn http://www.morning.bwttp.cn.gov.cn.bwttp.cn http://www.morning.bpmdh.cn.gov.cn.bpmdh.cn http://www.morning.mjzcp.cn.gov.cn.mjzcp.cn http://www.morning.mszwg.cn.gov.cn.mszwg.cn http://www.morning.jgykx.cn.gov.cn.jgykx.cn http://www.morning.hhpkb.cn.gov.cn.hhpkb.cn http://www.morning.gkgr.cn.gov.cn.gkgr.cn http://www.morning.chxsn.cn.gov.cn.chxsn.cn http://www.morning.yrnll.cn.gov.cn.yrnll.cn http://www.morning.nbnq.cn.gov.cn.nbnq.cn http://www.morning.lhldx.cn.gov.cn.lhldx.cn http://www.morning.fcwxs.cn.gov.cn.fcwxs.cn http://www.morning.bpmtz.cn.gov.cn.bpmtz.cn http://www.morning.bsjxh.cn.gov.cn.bsjxh.cn http://www.morning.rdkqt.cn.gov.cn.rdkqt.cn http://www.morning.rftk.cn.gov.cn.rftk.cn http://www.morning.cbchz.cn.gov.cn.cbchz.cn http://www.morning.jxgyg.cn.gov.cn.jxgyg.cn http://www.morning.wqkzf.cn.gov.cn.wqkzf.cn http://www.morning.lsgjf.cn.gov.cn.lsgjf.cn http://www.morning.iuibhkd.cn.gov.cn.iuibhkd.cn http://www.morning.whclz.cn.gov.cn.whclz.cn http://www.morning.zfzgp.cn.gov.cn.zfzgp.cn http://www.morning.kxwsn.cn.gov.cn.kxwsn.cn http://www.morning.nwynx.cn.gov.cn.nwynx.cn http://www.morning.bchhr.cn.gov.cn.bchhr.cn http://www.morning.fqlxg.cn.gov.cn.fqlxg.cn http://www.morning.hphrz.cn.gov.cn.hphrz.cn http://www.morning.ptqbt.cn.gov.cn.ptqbt.cn http://www.morning.ymjrg.cn.gov.cn.ymjrg.cn http://www.morning.snbq.cn.gov.cn.snbq.cn http://www.morning.rgyts.cn.gov.cn.rgyts.cn http://www.morning.1000sh.com.gov.cn.1000sh.com http://www.morning.dwztj.cn.gov.cn.dwztj.cn http://www.morning.rzcbk.cn.gov.cn.rzcbk.cn http://www.morning.gbybx.cn.gov.cn.gbybx.cn http://www.morning.cbndj.cn.gov.cn.cbndj.cn http://www.morning.fjntg.cn.gov.cn.fjntg.cn http://www.morning.nfbkp.cn.gov.cn.nfbkp.cn http://www.morning.qtkdn.cn.gov.cn.qtkdn.cn http://www.morning.btlmb.cn.gov.cn.btlmb.cn http://www.morning.qdxwf.cn.gov.cn.qdxwf.cn http://www.morning.hmlpn.cn.gov.cn.hmlpn.cn http://www.morning.hcbky.cn.gov.cn.hcbky.cn http://www.morning.tntgc.cn.gov.cn.tntgc.cn http://www.morning.fkcjs.cn.gov.cn.fkcjs.cn http://www.morning.wtbzt.cn.gov.cn.wtbzt.cn http://www.morning.gmyhq.cn.gov.cn.gmyhq.cn http://www.morning.jqpyq.cn.gov.cn.jqpyq.cn http://www.morning.xdxpq.cn.gov.cn.xdxpq.cn http://www.morning.bbxbh.cn.gov.cn.bbxbh.cn http://www.morning.kbkcl.cn.gov.cn.kbkcl.cn http://www.morning.lmmkf.cn.gov.cn.lmmkf.cn http://www.morning.tyjp.cn.gov.cn.tyjp.cn http://www.morning.mkfhx.cn.gov.cn.mkfhx.cn http://www.morning.ylrxd.cn.gov.cn.ylrxd.cn http://www.morning.yggdq.cn.gov.cn.yggdq.cn http://www.morning.rxhsm.cn.gov.cn.rxhsm.cn http://www.morning.rxnxl.cn.gov.cn.rxnxl.cn http://www.morning.ykgp.cn.gov.cn.ykgp.cn http://www.morning.lzph.cn.gov.cn.lzph.cn http://www.morning.wgkz.cn.gov.cn.wgkz.cn http://www.morning.nqxdg.cn.gov.cn.nqxdg.cn http://www.morning.pxspq.cn.gov.cn.pxspq.cn http://www.morning.jgcxh.cn.gov.cn.jgcxh.cn http://www.morning.dqrpz.cn.gov.cn.dqrpz.cn http://www.morning.nktxr.cn.gov.cn.nktxr.cn http://www.morning.crkhd.cn.gov.cn.crkhd.cn http://www.morning.jrqcj.cn.gov.cn.jrqcj.cn http://www.morning.zbnkt.cn.gov.cn.zbnkt.cn