我想知道有什么方法可以检查文件中数据库的增长情况吗?
发布于 2013-01-13 20:14:14
这很有趣。我刚刚回答了一个问题,在这里我发布了一个查询,您可以运行它来告诉您每个存储引擎按数据库占用多少磁盘空间。
查看Jan 13, 2013:将备份大小转换为数据库大小上的那篇文章
本质上,您需要参考information_schema获取mysqld所查看的数据和索引大小。下面是一些如何获取所需信息的示例:
要获得所有MyISAM表使用的磁盘空间的数量,请运行以下命令:
SELECT
myisam_bytes/power(1024,1) myisam_kb,
myisam_bytes/power(1024,2) myisam_mb,
myisam_bytes/power(1024,3) myisam_gb
FROM
(
SELECT SUM(data_length+index_length) myisam_bytes
FROM information_schema.tables WHERE engine='MyISAM'
AND table_schema NOT IN ('information_schema','mysql')
) A;通过数据库获得这个
SELECT db,
myisam_bytes/power(1024,1) myisam_kb,
myisam_bytes/power(1024,2) myisam_mb,
myisam_bytes/power(1024,3) myisam_gb
FROM
(
SELECT table_schema db,SUM(data_length+index_length) myisam_bytes
FROM information_schema.tables WHERE engine='MyISAM'
AND table_schema NOT IN ('information_schema','mysql')
GROUP BY table_schema
) A;通过数据库和引擎获得这个
SELECT db,engine,
myisam_bytes/power(1024,1) myisam_kb,
myisam_bytes/power(1024,2) myisam_mb,
myisam_bytes/power(1024,3) myisam_gb
FROM
(
SELECT table_schema db,engine,SUM(data_length+index_length) myisam_bytes
FROM information_schema.tables WHERE engine='MyISAM'
AND table_schema NOT IN ('information_schema','mysql')
GROUP BY table_schema,engine
) A;要获得所有InnoDB表使用的磁盘空间的数量,请运行以下命令:
SELECT
innodb_bytes/power(1024,1) innodb_kb,
innodb_bytes/power(1024,2) innodb_mb,
innodb_bytes/power(1024,3) innodb_gb
FROM
(
SELECT SUM(data_length+index_length) innodb_bytes
FROM information_schema.tables WHERE engine='InnoDB'
) A;通过数据库获得这个
SELECT db,
innodb_bytes/power(1024,1) innodb_kb,
innodb_bytes/power(1024,2) innodb_mb,
innodb_bytes/power(1024,3) innodb_gb
FROM
(
SELECT table_schema db,SUM(data_length+index_length) innodb_bytes
FROM information_schema.tables WHERE engine='InnoDB'
GROUP BY table_schema
) A;通过数据库和引擎获得这个
SELECT db,engine,
innodb_bytes/power(1024,1) innodb_kb,
innodb_bytes/power(1024,2) innodb_mb,
innodb_bytes/power(1024,3) innodb_gb
FROM
(
SELECT table_schema db,engine,
SUM(data_length+index_length) innodb_bytes
FROM information_schema.tables WHERE engine='InnoDB'
GROUP BY table_schema,engine
) A;我以前已经讨论过很多次了
Sep 13, 2011:确定支持的最大数据库和表大小以及当前大小Dec 01, 2011:MySQL工作台数据库大小Jul 07, 2012:查找我服务器上最大的数据库请记住,这些查询将报告数据和索引占用了多少实际空间。实际的文件大小可能实际上比information_schema说的要大。在这种情况下,必须对每个具有碎片的表运行OPTIMIZE TABLE tblname;。
例如,假设您有一个MyISAM表mydb.mytable并运行以下查询:
SELECT
myisam_bytes/power(1024,1) myisam_kb,
myisam_bytes/power(1024,2) myisam_mb,
myisam_bytes/power(1024,3) myisam_gb
FROM information_schema.tables
WHERE table_schema='mydb'
AND table_name='mytable';转到操作系统并运行以下内容:
ls -l mytable.MY[DI] (Linux)dir mytable.MY* (视窗)列出的字节之和可能比information_schema说的要多。如果是这样的话,请运行OPTIMIZE TABLE tblname;并运行相同的查询,您可能会注意到表会缩小。
尽管如此,请确保定期对所有经历大量更新、删除和插入的表运行OPTIMIZE TABLE。
https://dba.stackexchange.com/questions/31864
复制相似问题