首页 > 代码库 > mysql 实例下具体查看库,和表的大小
mysql 实例下具体查看库,和表的大小
1.mysql 查看实例下,每个库的大小 select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),‘ MB‘) as data_size, concat(truncate(sum(index_length)/1024/1024,2),‘MB‘) as index_size from information_schema.tables group by TABLE_SCHEMA order by data_length desc; 2.mysql 查看具体某个库里面的某个表的大小。 select concat(round(sum(DATA_LENGTH/1024/1024),2),‘M‘) from tables where table_schema=\"${db}\" AND table_name=\"${table}\" 3.查看mysql 实例下,所有库下的每个表的大小。 #!/bin/bash >allsize.txt for n in `cat mysqlbackuplist.txt` do echo ========= ${n} ========= >>allsize.txt for db in `mysql -uroot -ppassword -h$n -e ‘show databases;‘ |awk ‘NR>1{print $1}‘|egrep -v ‘schema|tmp|sys|innodb|mysql|tigasedb‘` do >${db}size.txt echo ========= ${db} ========= echo ========= ${db} ========= >>allsize.txt for table in `mysql -uroot -ppassword -h$n -e "use ${db}; show tables"` do selectsql="select concat(round(sum(DATA_LENGTH/1024/1024),2),‘M‘) from tables where table_schema=\"${db}\" AND table_name=\"${table}\";" mysql -uroot -ppassword -h$n -e "use information_schema; $selectsql" |awk -v table=$table ‘NR>1{print table " " $1}‘ >>${db}size.txt done cat ${db}size.txt|sort -k 2 -rn >> allsize.txt done done
本文出自 “奋斗吧” 博客,请务必保留此出处http://lvnian.blog.51cto.com/7155281/1953555
mysql 实例下具体查看库,和表的大小
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。