Home > Database > Mysql Tutorial > body text

How to get the size of a table in a MySQL database?

PHPz
Release: 2023-08-25 15:05:02
forward
1389 people have browsed it

How to get the size of a table in a MySQL database?

To get the size of the tables in the MySQL database, you can use "information_schema.tables".

This is the syntax to get the size of all 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;
Copy after login

Let us apply the above syntax to get the size of the table.

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;
Copy after login

Example output.

+------------------------------------------------------------------+-----------------+
| 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)
Copy after login

The above is the detailed content of How to get the size of a table in a MySQL database?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!