mysql查看数据库大小以及使用情况?

小草鱼2年前Linux技术相关946


一、用SQL命令查看Mysql数据库大小

要想知道每个数据库的大小的话,步骤如下:


1、进入information_schema 数据库(存放了其他的数据库的信息)

use information_schema;


2、查询所有数据的大小

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;


3、查看指定数据库的大小

比如查看数据库home的大小


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


4、查看指定数据库的某个表的大小

比如查看数据库home中 members 表的大小


select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home' and table_name='members';


查看MySql数据空间使用情况:


information_schema是MySQL的系统数据库,information_schema里的tables表存放了整个数据库各个表的使用情况。


可以使用sql来统计出数据库的空间使用情况,相关字段:


table_schema:数据库名


table_name:表名


table_rows:记录数


data_length:数据大小


index_length:索引大小


二、使用空间

1、统计表使用空间

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


| data |


| 0.02mb |


1 row in set (0.00 sec)


2、统计数据库使用空间

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


3、统计所有数据使用空间

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;


相关文章

Linux的最基础常用操作命令

Linux的最基础常用操作命令

Linux下,一切皆文件;Linux系统的文件目录以及存储的内容:/boot:存放启动linux所必须的文件,包括内核文件,启动菜单配置文件;/bin:linux下最基本的用户命令,普通用户都有权执行...

Linux修改SSH连接数 重启SSH服务

Linux修改SSH连接数 重启SSH服务系统 linux,增加SSH终端连接数最大为1000个解决方案:vi /etc/ssh/sshd_config输入/MaxStartups 定位到如下并修改1...

centos7 校对日期和时间

1、使用date命令查看当前系统时间2、使用命令rm -f /etc/localtime删除本地时间文件。3、使用命令cp /usr/share/zoneinfo/Asia/Shanghai /etc...

ubuntu18.04 启用root账户 并ssh远程访问

Ubuntu 16.04 同样适用该方法安装sshapt install openssh-server  apt-get install openssh-server二、更改Ubu...

linux系统释放内存的方法

运行下面语句清缓存时,报错:-bash: /proc/sys/vm/drop_caches: Permission deniedsudo echo 1 > /proc/sys/vm/drop_c...

Linux下的TCP测试工具

Linux下的TCP测试工具如何在 Linux 上安装 tcpping测量到远程主机的网络延迟的一种常用方法是使用ping应用程序。该ping工具依赖 ICMP ECHO 请求和回复数据包来测量远程主...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。