Specific view of the library, and the size of the table under MySQL instance

Source: Internet
Author: User

1.mysql  View instance, the size of each library 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_sizefrom  information_schema.tablesgroup by table_schemaorder by data_length desc;2.mysql   View the size of a table within a specific library. Select concat (Round (sum (data_length/1024/1024), 2), ' M ')  from tables where table_schema =\ "${db}\"  and table_name=\ "${table}\" 3. View the size of each table under the mysql  instance, under all libraries. #!/bin/bash>allsize.txtfor 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


This article is from the "Struggle Bar" blog, please be sure to keep this source http://lvnian.blog.51cto.com/7155281/1953555

Specific view of the library, and the size of the table under MySQL instance

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.