Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
133 views
in Technique[技术] by (71.8m points)

sql - Query to determine the size of tables in a database? (mysql)

The website "How to calculate the MySQL database size" gives two queries:

Determine sizes of all databases

SELECT table_schema "Data Base Name", SUM( data_length + index_length) / 1024 / 1024 
"Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema ;

Determine size of all tables in a database

SELECT TABLE_NAME, table_rows, data_length, index_length, 
round(((data_length + index_length) / 1024 / 1024),2) "Size in MB"
FROM information_schema.TABLES WHERE table_schema = "schema_name";

The first query works correctly, but the second query doesn't produce a result set. It just shows the names of the fields without any rows. How can I modify the 2nd query to correctly show the size of sizes of my tables in my database.

question from:https://stackoverflow.com/questions/8363435/query-to-determine-the-size-of-tables-in-a-database-mysql

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Replace "schema_name" with the name of one of your databases.

And use single-quotes for string literals, not double-quotes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...