Technologie
Photo of author

How to Check MySQL Database Size in Linux

Tutorial MySQL – Check the size of all Databases

First, access the MySQL command-line (replace «root» by your mysql username) :

$ mysql -u root -p

Run this command to check the size of all the mySQL Database Size in MB :

SELECT table_schema AS "DATABASE NAME", SUM(data_length + index_length) / 1024 / 1024 AS "Size IN (MB)" FROM information_schema.TABLES GROUP BY table_schema;

Here is the command outpout :

+--------------------+----------+
| Database           | Size(MB) |
+--------------------+----------+
| searx              |    142.5 |
| glpi               |   2858.7 |
| wordpress          |   1024.0 |
+--------------------+----------+

In our example, a table showing the size of all MySQL databases was presented.

Database Size in GB :

SELECT table_schema "DATABASE NAME", sum(data_length + index_length)/1024/1024/1024 "SIZW IN GB" FROM information_schema.TABLES GROUP BY table_schema;

Tutorial MySQL – Check the size of a specific Databases

First, access the MySQL command-line (replace «root» by your mysql username) :


mysql -u root -p

Run this command to check the size of a MySQL Specific Database Size in MB :

SELECT table_schema "Database", ROUND(SUM(data_length + index_length) / 1024 / 1024, 1) "Size(MB)" FROM information_schema.tables 
WHERE table_schema = "PUT-DATABASE-NAME-HERE";

Here is the command output:

+--------------------+----------+
| Database           | Size(MB) |
+--------------------+----------+
| searx              |    142.3 |
+--------------------+----------+

In our example, we verified that the MySQL database named searx has 142.3 Megabytes.

If you run into some problems, you can type «systemctl status apache2», this should give you information about the problem.

Specific Database Size in GB :

SELECT table_schema "database", sum(data_length + index_length)/1024/1024/1024 "size in GB" FROM information_schema.TABLES WHERE table_schema='linuxfaq_data' GROUP BY table_schema;

Find tables size in MB :

To find out the size of a single MySQL database called searx (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 = "searx"
ORDER BY (data_length + index_length) DESC;

Output will look like this :

+-----------------------+--------------+
| Table Name            | Size in (MB) |
+-----------------------+--------------+
| identities            |         2.56 |
| options               |         2.09 |
| searches              |         1.56 |
| cache_shared          |         0.09 |
| dicrionary            |         0.06 |
| system                |         0.05 |
+-----------------------+--------------+

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

outpout will look like this :

208K    /var/lib/mysql/speedtest
1.4M    /var/lib/mysql/mysql
8.0K    /var/lib/mysql/performance_schema
36M     /var/lib/mysql/getlucky
13M     /var/lib/mysql/blogdb
31M     /var/lib/mysql/searx
265M    /var/lib/mysql

Laisser un commentaire