This article explains how to check the size of a MySQL database using the SSH command line interface.
Steps to Check MySQL Database Size via SSH:
- Log in to your server via SSH using the root user or a user with MySQL access.
- Access the MySQL prompt by running the following command:
mysql -u username -p
Replace username with your actual MySQL username. You’ll be prompted to enter the password.
- To check the size of all databases, run the following SQL query:
SELECT table_schema AS “Database”, ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS “Size (MB)” FROM information_schema.TABLES GROUP BY table_schema;
- To check the size of a single database, replace your_database_name with the actual database name in the query below:
SELECT table_schema AS “Database”, ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS “Size (MB)” FROM information_schema.TABLES WHERE table_schema = ‘your_database_name’;
- To check the size of individual tables within a specific database, use:
SELECT table_name AS “Table”, ROUND((data_length + index_length) / 1024 / 1024, 2) AS “Size (MB)” FROM information_schema.TABLES WHERE table_schema = ‘your_database_name’ ORDER BY (data_length + index_length) DESC;
By following the steps above, you can easily check the size of your MySQL databases and tables using the SSH command line. For more MySQL tips and tutorials, visit our Knowledge Base section.
If you want to use phpMyAdmin to determine the size of the MySQL database then Read this How to check the size of MySQL database using phpMyAdmin