How to get size of a mysql database?
Suppose the target database is called "v3".
633
votes
For specific table / specific database size the script provided here will help, the information is calculated from information_schema.tables table, see the detailed answer here rathishkumar.in/2017/12/…
– Rathish Kumar B
9 Answers
1383
votes
Run this query and you'll probably get what you're looking for:
SELECT table_schema "DB Name",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB"
FROM information_schema.tables
GROUP BY table_schema;
This query comes from the mysql forums, where there are more comprehensive instructions available.
118
votes
It can be determined by using following MySQL command
SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema
Result
Database Size (MB)
db1 11.75678253
db2 9.53125000
test 50.78547382
Get result in GB
SELECT table_schema AS "Database", SUM(data_length + index_length) / 1024 / 1024 / 1024 AS "Size (GB)" FROM information_schema.TABLES GROUP BY table_schema
35
votes
27
votes
21
votes
To get a result in MB:
SELECT
SUM(ROUND(((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024), 2)) AS "SIZE IN MB"
FROM INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA = "SCHEMA-NAME";
To get a result in GB:
SELECT
SUM(ROUND(((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024 / 1024), 2)) AS "SIZE IN GB"
FROM INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA = "SCHEMA-NAME";
17
votes
mysqldiskusage --server=root:MyPassword@localhost pics
+----------+----------------+
| db_name | total |
+----------+----------------+
| pics | 1,179,131,029 |
+----------+----------------+
If not installed, this can be installed by installing the mysql-utils
package which should be packaged by most major distributions.
10
votes
First login to MySQL using
mysql -u username -p
Command to Display the size of a single Database along with its table in MB.
SELECT table_name AS "Table",
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)"
FROM information_schema.TABLES
WHERE table_schema = "database_name"
ORDER BY (data_length + index_length) DESC;
Change database_name to your Database
Command to Display all the Databases with its size in MB.
SELECT table_schema AS "Database",
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)"
FROM information_schema.TABLES
GROUP BY table_schema;