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

小草鱼3年前Linux技术相关1832


一、用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;


相关文章

ubuntu 20.04版本 命令行配置ip地址

修改网卡配置(电脑关机重启后仍旧有效)编辑网络配置文件root@it:~# vim /etc/netplan/00-installer-config.yaml# This is the network...

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

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

docker的学习文档

docker的学习文档

docker容器学习笔记.docx一、Docker概述1.Docker为什么会出现?一款产品: 开发–上线 两套环境!应用环境,应用配置!开发 — 运维。 问题:我在我的电脑上可以允许!版本更新,导致...

Ubuntu删除多余内核的办法---转载

第一步:查看当前内核rew $ uname -a Linux rew 4.15.0-42-generic #45~16.04.1-Ubun...

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

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

git简单使用说明

git简单使用说明

功能:版本控制;--》多人开发必须使用版本控制;git安装包安装完毕后,空白地方鼠标右键会有git bash here选项,点击进入后,可以使用Linux命令;git config -l:查看个人配置...

发表评论    

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