≡ Menu

How to check MySQL database disk usage?

Question – I need to check how much disk space is used by my MySQL databases. Is there a Linux command that can check this?

There is a Linux command that can output the disk space used by any directory. This command is called du which stands for disk usage.

To check the disk usage on any directory, use the following code:

du -sh /path/to/directory

On my Linux CentOS box, MySQL stores all of its databases in the following directory:

/var/lib/mysql

To check the disk usage of all of your databases, use the following command:

du -sh /var/lib/mysql

On my machine, this outputs:

root@server [~]# du -sh /var/lib/mysql
30G     /var/lib/mysql
root@server [~]#

This shows that all of my databases together use 30 giga bytes of disk space.

MySQL stores each individual database in a separate directory under /var/lib/mysql.

For example my database called ewhathow_database is stored under the following directory:

/var/lib/mysql/ewhathow_database

To check the disk usage of an individual database, just pass that directory to the command du.

du -sh /var/lib/mysql/ewhathow_database/

This outputs something like the following:

root@server [~]# du -sh /var/lib/mysql/ewhathow_database/
40K     /var/lib/mysql/ewhathow_database/
root@server [~]#

So, my database ewhathow_database takes only 40 kilo bytes of disk space!

Now to explain the du command arguments:

-h: This argument instructs du to output the size in a human readable format. So instead of outputting 1024, it will output 1K.
-s: This argument instructs du to summarize the output as a total

Incoming search terms:

  • how to check database disk space in fedora linu (1)
  • mysqldiskusage example (1)

Comments on this entry are closed.