How to View the Size of a MySQL Database
Linode
Linode Staff
How can I view the size of my databases on my Linode?
1 Reply
eruzanski
Linode Staff
A Quick Introduction
If you're yet to get started with MySQL, you can check out one of the links included below. Otherwise, this post will assume you have one, if not several, existing MySQL databases on your Linode.
Logging Into MySQL
Login to MySQL by running:
sudo mysql -u <mysql-username> -p <mysql-user-password>
If you get an error with MySQL
, try substituting mariadb
:
sudo mariadb -u <mariadb-username> -p <mariadb-user-password>
Returning the Size of all Databases
Run the following queries to return the size of each database:
For returning the sizes in MB:
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;
For returning the sizes in GB:
SELECT table_schema "DB Name",
ROUND(SUM(data_length + index_length) / 1024 / 1024 / 1024, 1) "DB Size in GB"
FROM information_schema.tables
GROUP BY table_schema;
The output should look like this:
+--------------------+---------------+
| DB Name | DB Size in MB |
+--------------------+---------------+
| information_schema | 0.2 |
| mysql | 2.1 |
| performance_schema | 0.0 |
+--------------------+---------------+
3 rows in set (0.011 sec)
A quick note, this will only return the databases that the MySQL
or MariaDB
user has privilege to interact with.