Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get mysql table size in GB

Tags:

mysql

Just ended up with calculating the size of MySQL table in GB with the following query.

SELECT (data_length+index_length)/power(1024,3) tablesize_gb FROM information_schema.tables WHERE table_schema='db' and table_name='tablename'

Is it possible to get the size of a MySQL row in GB.

Or how to get the avg row size for the table in GB.

like image 740
Parthi04 Avatar asked Mar 30 '13 05:03

Parthi04


People also ask

How do I find the table size in MySQL GB?

To check the sizes of all of the tables in a specific database, at the mysql> prompt, type the following command. Replace database_name with the name of the database that you want to check: Copy SELECT table_name AS "Table", ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)" FROM information_schema.

How do I know what size my DB is GB?

If you need to check a single database, you can quickly find the SQL Server database sizein SQL Server Management Studio (SSMS): Right-click the database and then click Reports -> Standard Reports -> Disk Usage. Alternatively, you can use stored procedures like exec sp_spaceused to get database size.

What is table size in MySQL?

Table Size Limits. MyISAM tables have a default limit set to 256TB for data and index files, which you can change to 65,536TB maximum. InnoDB maximum size for tables is 256TB, which corresponds to the full tablespace size.


3 Answers

To get the average row length (including overhead), use the AVG_ROW_LENGTH column in the information schema table:

select AVG_ROW_LENGTH from INFORMATION_SCHEMA.tables;

As far as I'm aware, there's no way to calculate the exact actual size of a single, specific row in MySQL.

like image 107
nneonneo Avatar answered Oct 25 '22 15:10

nneonneo


Hi this might do the trick, we had a similar issue and had to find out which types of rows take up the most space. That's why here with a group by...

SELECT groupval, (sum(length(somefield) + length(someotherfield)) / 1024) / 1024 as "fields_size_mb"
FROM table
GROUP BY groupval
ORDER BY fields_size_mb desc;
like image 29
Ranil Wijeyratne Avatar answered Oct 25 '22 14:10

Ranil Wijeyratne


SELECT 
     table_name AS `Table`, 
     round(((data_length + index_length) / 1024 / 1024 ), 2) as `Size in MB`,
     round((AVG_ROW_LENGTH / 1024), 2) as `Avg row size in KB`
FROM information_schema.TABLES WHERE table_schema = 'your_db_name'
ORDER BY `Size in MB` DESC
like image 28
Entity Avatar answered Oct 25 '22 13:10

Entity