常见select查询总结

常见select查询总结
周万春

查看单个数据库数据大小
[root@db01 ~]# mysql.dba -e "select table_name,concat(round((data_length + index_length + data_free)/1024/1024,2),'MB') from information_schema.tables where table_schema='world';"
+-----------------+--------------------------------------------------------------------------+
| table_name      | concat(round((data_length + index_length + data_free)/1024/1024,2),'MB') |
+-----------------+--------------------------------------------------------------------------+
| city            | 0.52MB                                                                   |
| country         | 0.09MB                                                                   |
| countrylanguage | 0.16MB                                                                   |
+-----------------+--------------------------------------------------------------------------+


查看单张表数据大小
[root@db01 ~]# mysql.dba -e "select table_name,concat(round((data_length + index_length + data_free)/1024/1024,2),'MB') from information_schema.tables where table_schema='world' and table_name='city';"
+------------+--------------------------------------------------------------------------+
| table_name | concat(round((data_length + index_length + data_free)/1024/1024,2),'MB') |
+------------+--------------------------------------------------------------------------+
| city       | 0.52MB                                                                   |
+------------+--------------------------------------------------------------------------+


查看所有数据库的大小
[root@db01 ~]# mysql.dba -e "select table_schema,concat(round(sum((data_length + index_length + data_free)/1024/1024),2),'MB') as data_size from information_schema.tables group by table_schema;"
+--------------------+-----------+
| table_schema       | data_size |
+--------------------+-----------+
| app01              | 0.02MB    |
| information_schema | 80.16MB   |
| mysql              | 6.51MB    |
| performance_schema | 0.00MB    |
| sakila             | 14.45MB   |
| student            | 0.06MB    |
| sys                | 0.02MB    |
| world              | 0.77MB    |
+--------------------+-----------+
原文地址:https://www.cnblogs.com/zhouwanchun/p/12911330.html