如何获取MySQL数据库中表的大小?

数据库数据库 2023-08-31 03:28:39 917
摘要: 要获取MySQL数据库中表的大小,可以使用“information_schema.tables”。这是获取所有表大小的语法。SELECTTABLE_NAMEAS`ALLTABLESNAME`,ROUND((DATA_LENGTH+INDEX_LENGTH)/1024/1024)AS`TABLESIZEIN(M...

如何获取MySQL数据库中表的大小?

要获取MySQL数据库中表的大小,可以使用“information_schema.tables”。

这是获取所有表大小的语法。

SELECT TABLE_NAME AS `ALLTABLESNAME`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `TABLESIZEIN(MB)`
   FROM information_schema.TABLES WHERE TABLE_SCHEMA = "yourDatabaseName"
   ORDER BY (DATA_LENGTH + INDEX_LENGTH) ASC;

让我们应用上述语法来获取表的大小。

mysql> SELECT TABLE_NAME AS `ALLTABLESNAME`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `TABLESIZEIN(MB)`
   ->  FROM information_schema.TABLES WHERE TABLE_SCHEMA = "business"
   -> ORDER BY (DATA_LENGTH + INDEX_LENGTH) ASC;

示例输出。

+------------------------------------------------------------------+-----------------+
| ALLTABLESNAME                                                    | TABLESIZEIN(MB) |
+------------------------------------------------------------------+-----------------+
| studentrecordwithmyisam                                          |               0 |
| querydatedemo                                                    |               1 |
| rownumberdemo                                                    |               0 |
| secondtable                                                      |               0 |
| spacecolumn                                                      |               2 |
| table1                                                           |               0 |
| tbldemotrail                                                     |               2 |
| tblstudent                                                       |               0 |
| timestamptodatedemo                                              |               1 |
| uniqueconstraintdemo                                             |               0 |
| usernameandpassworddemo                                          |               2 |
| addingunique                                                     |               5 |
| bookindexes                                                      |               0 |
| tblf                                                             |               0 |
| uniquedemo                                                       |               2 |
| multipleindexdemo                                                |               0 |
| uniquedemo1                                                      |               0 |
| foreigntable                                                     |               5 |
| tabledemo2                                                       |               0 |
| foreigntabledemo                                                 |               2 |
| studentenrollment                                                |               0 |
| tabledemo3                                                       |               0 |
| duplicatebookindexes                                             |               0 |
| clonestudent                                                     |               2 |
| student                                                          |               0 |
+------------------------------------------------------------------+-----------------+
26 rows in set (10.29 sec)

以上就是如何获取MySQL数据库中表的大小?的详细内容,更多请关注其它相关文章!