Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Databases»MySQL»How to Check MySQL Database & Tables Size

    How to Check MySQL Database & Tables Size

    RahulBy RahulJuly 29, 20152 Mins ReadUpdated:January 4, 2019

    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
    Previous ArticleHow to Install Libreoffice 4.3 on Ubuntu 12.04 and 14.04 LTS
    Next Article How to Install Python 3.7 on Ubuntu, Debian and LinuxMint

    Related Posts

    How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Updated:April 7, 20227 Mins Read

    How To Install MySQL Server on Ubuntu 22.04

    Updated:April 6, 20224 Mins Read

    How To Install LAMP Stack on Ubuntu 22.04 LTS

    Updated:April 20, 20225 Mins Read

    How To Install MariaDB on Debian 11

    4 Mins Read

    How to Install Redis on Debian 11 Linux

    Updated:September 16, 20213 Mins Read

    How to Check the PostgreSQL Version

    Updated:August 6, 20212 Mins Read

    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

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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