How to Check MySQL Database Size in Linux

In this article, I will show you how to check the size of MySQL/MariaDB databases and tables via the MySQL shell. You will learn how to determine the real size of a database file on the disk as well as size of data that it present in a database.

Read Also: 20 MySQL (Mysqladmin) Commands for Database Administration in Linux

By default MySQL/MariaDB stores all the data in the file system, and the size of data that exists on the databases may differ from the actual size of Mysql data on the disk that we will see later on.

In addition, MySQL uses the information_schema virtual database to store information about your databases and other settings. You can query it to gather information about size of databases and their tables as shown.

# mysql -u root -p
MariaDB [(none)]> SELECT table_schema AS "Database Name", 
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size in (MB)" 
FROM information_schema.TABLES 
GROUP BY table_schema; 
Check MySQL Database Size
Check MySQL Database Size

To find out the size of a single MySQL database called rcubemail (which displays the size of all tables in it) use the following mysql query.

MariaDB [(none)]> SELECT table_name AS "Table Name",
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size in (MB)"
FROM information_schema.TABLES
WHERE table_schema = "rcubemail"
ORDER BY (data_length + index_length) DESC;
Check Size of MySQL Database
Check Size of MySQL Database

Finally, to find out the actual size of all MySQL database files on the disk (filesystem), run the du command below.

# du -h /var/lib/mysql
Check MySQL Size on Disk
Check MySQL Size on Disk

You might also like to read these following MySQL related articles.

  1. 4 Useful Commandline Tools to Monitor MySQL Performance in Linux
  2. 12 MySQL/MariaDB Security Best Practices for Linux

For any queries or additional ideas you want to share regarding this topic, use the feedback form below.

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.