Open In App

How to Check MySQL Database

SQL stands for Structured Query Language which is a computer language for storing, manipulating, and retrieving data stored in relational database management systems (RDBMS). SQL was developed at IBM by Donald Chamberlin, Donald C. Messerli, and Raymond F. Boyce in the year 1970s. MySQL is an open-source Relational Database Management System that stores data in a structured format using rows and columns. MYSQL language is easy to use as compared to other programming languages like C, C++, Java, etc. By learning some basic commands we can work, create, and interact with the Database.

A table is used to organize data in the form of rows and columns and is used for both storing and displaying records in the structure format. It is similar to worksheets in the spreadsheet application. A table creation command requires three things:



MySQL allows us to create a table in the database mainly in two ways:

To get the size of a MySQL database, you can use various methods, including SQL queries or checking the file system. Here are a few ways to accomplish this:



Method 1: Using SQL Query

You can use the information_schema database to query the size of a MySQL database:

SELECT table_schema AS "Database Name", 
SUM(data_length + index_length) / (1024 * 1024) AS "Size (MB)"
FROM information_schema.tables
GROUP BY table_schema;

In summary, the query retrieves the size of each database in megabytes, combining the data and index lengths of its tables. The result set will display the “Database Name” and the corresponding “Size (MB)” for each database on your MySQL.

Output:

This query sums up the data length and index length for each table in the specified database, providing the total size in MB.

Method 2: Using MySQL

If you’re using the MySQL Shell, you can run the following command:

SHOW TABLE STATUS LIKE ‘DB NAME’;

Example:

SHOW TABLE STATUS LIKE 'student';

Output:

Explanation:

This command will display detailed information about each table in the specified database, including the data length and index length.

The result will provide information about all the table in the specified database, details such as the table name, engine, version, row count, data length, index length, etc.

Please Note that the output of this query can be very Large, so you might want to focus on the particular columns that are most relevant according to your need.

Method 3: Third-Party DB Tools

There are few third-party tools available that can provide the size and health of your MySQL databases. Some popular tools are:

Conclusion

Choose the method that best fits your needs and the tools available in your environment. Keep in mind that the SQL queries provide more accurate information about the logical size of the data, while file system inspection provides information about the physical size on disk. You may get large information which is not needed so filter it out according to your need. MySQL Workbench or executing SQL queries and command line commands, understanding your database size helps you make informed decisions about resource allocation and data management.

Article Tags :