mysql查询数据库大小常用语句

1,查询一个实例的所有库的数据的大小总和(其实真实情况没人这么看,都会去看库文件大小)
mysql> select concat(round(sum(DATA_LENGTH/1024/1024/1024),2),'GB') as data from information_schema.tables;
+----------+
| data |
+----------+
| 135.92GB |
+----------+
1 row in set, 2 warnings (6.38 sec)
2,查询指定数据库的大小,例如:数据库kiradb
mysql> select concat(round(sum(DATA_LENGTH/1024/1024/1024),2),'GB') as data from information_schema.tables where table_schema='kiradb';
+----------+
| data |
+----------+
| 124.74GB |
+----------+
1 row in set (4.07 sec)
3,查看指定数据库的表的大小,比如说:数据库kiradb,表job
mysql> select concat(round(sum(DATA_LENGTH/1024/1024/1024),2),'GB') as data from information_schema.tables where table_schema='kiradb' and table_name='job';
+--------+
| data |
+--------+
| 7.45GB |
4,查询一个实例的所有库的数据和索引的大小之和
mysql> select concat(round(sum((DATA_LENGTH+INDEX_LENGTH)/1024/1024),2),'MB') as data from information_schema.TABLES;
5,查询TOP20大表
select table_schema,table_name,(data_length + index_length) / 1024 / 1024 /1024 as total_GB from information_schema.tables order by total_GB desc limit 20;
6,查询整个库的表数【估算】
select count(table_name),table_schema from information_schema.tables group by table_schema;
7,检查user及权限
root@localhost:t2 10:42:56>select user,host from mysql.user;
root@localhost:t2 10:42:56>select concat(  'show grants for ''', user, '''@''', host, ''';' ) as query from mysql.user;
| SHOW GRANTS FOR 'dbauser'@'%';      |
| SHOW GRANTS FOR 'root'@'%';         |
root@localhost:t2 10:42:56>show grants for 'dbauser'@'%';
8, 查看连接上服务器上数据库的用户
1)从数据库中看
root@localhost:(none) 11:00:19>show processlist;
2)从系统中查看
[root@pmos ~]# mysqladmin -uroot -proot -hlocalhost processlist




来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31447263/viewspace-2144211/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31447263/viewspace-2144211/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值