Close Menu
    Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»Databases»MySQL»How to Check MySQL Database & Tables Size

    How to Check MySQL Database & Tables Size

    By RahulJanuary 4, 20192 Mins Read

    MySQL is a Relational Database Management System, widely used as a database system for Linux systems. This article will help you to calculate the size of tables and database in MySQL or MariaDB servers though SQL queries. MySQL stored all the information related to tables in a database in the information_schema database. We will use the information_schema table to find tables and databases size.

    Check Single Database Size in MySQL

    This query will calculate the size of the single database in MySQL server. Please change ‘mydb‘ with your actual database name.

    SELECT table_schema "Database Name", SUM( data_length + index_length)/1024/1024
    "Database Size (MB)" FROM information_schema.TABLES where table_schema = 'mydb';
    
    +---------------+--------------------+
    | Database Name | Database Size (MB) |
    +---------------+--------------------+
    | mydb          |         0.15625000 |
    +---------------+--------------------+
    1 row in set (0.04 sec)
    

    Check ALL Databases Size in MySQL

    This query will calculate size of all databases in mysql server.

    SELECT table_schema "Database Name", SUM(data_length+index_length)/1024/1024
    "Database Size (MB)"  FROM information_schema.TABLES GROUP BY table_schema;
    
    +--------------------+--------------------+
    | Database Name      | Database Size (MB) |
    +--------------------+--------------------+
    | demodb             |         0.15625000 |
    | information_schema |         0.00976563 |
    | mydb               |         0.15625000 |
    | mysql              |         0.81098557 |
    | performance_schema |         0.00000000 |
    +--------------------+--------------------+
    5 rows in set (0.01 sec)
    

    Check Single Table Size in MySQL Database

    This query will calculate size of single table in a database in mysql server. Please change ‘mydb‘ with your actual database name and ‘table_one‘ with your actual table name.

    SELECT table_name "Table Name", table_rows "Rows Count", round(((data_length + index_length)/1024/1024),2)
    "Table Size (MB)" FROM information_schema.TABLES WHERE table_schema = "mydb" AND table_name ="table_one";
    
    +---------------------+------------+-----------------+
    | Table Name          | Rows Count | Table Size (MB) |
    +---------------------+------------+-----------------+
    | archive_one         |          8 |            0.09 |
    +---------------------+------------+-----------------+
    1 row in set (0.00 sec)
    

    Check All Table Size in MySQL Database

    This query will calculate size of all tables in a database in mysql server. Please change ‘mydb‘ with your actual database name. It will also list number of rows in each table.

    SELECT table_name "Table Name", table_rows "Rows Count", round(((data_length + index_length)/1024/1024),2)
    "Table Size (MB)" FROM information_schema.TABLES WHERE table_schema = "mydb";
    
    +----------------------+------------+-----------------+
    | Table Name           | Rows Count | Table Size (MB) |
    +----------------------+------------+-----------------+
    | table_one  	       |          8 |            0.09 |
    | table_two 	       |          0 |            0.02 |
    | table_three          |          0 |            0.02 |
    | table_four           |        174 |            0.03 |
    +----------------------+------------+-----------------+
    4 rows in set (0.00 sec)
    

    database MySQL size tables
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Working with Python FastAPI and MySQL

    Resolving MySQL ERROR 1041 (HY000): Out of Memory

    How to Calculate the MySQL Database Size

    View 3 Comments

    3 Comments

    1. Hugo Lossólli on November 7, 2018 7:37 pm

      Great work! Thanks Rahul!

      Reply
    2. bheema on August 19, 2018 9:05 am

      thanks

      Reply
    3. Fahad Ahammed on February 2, 2017 7:51 am

      Thank You.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Change Port in Next.Js
    • Ubuntu 24.04 LTS: The Future of Open-Source Excellence
    • How to Execute Linux Commands in Python
    • Creating MySQL User with GRANT OPTION
    • Where to find crontab (cron) logs in Ubuntu & Debian
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.