How to View the Size of a MySQL Database

Linode Staff

How can I view the size of my databases on my Linode?

1 Reply

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.

What Is MySQL: An Overview

Additional MySQL Guides

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.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct