Query the total size of all databases Here’s how: mysql> use information_schema; mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES; +-----------+ | data | +-----------+ | 3052.76MB | +-----------+ 1 row in set (0.02 sec) Count the amount of data in all libraries The amount of data in each table = AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH SELECT SUM(AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH)/1024/1024 AS total_mb FROM information_schema.TABLES Statistics of each library size: SELECT table_schema,SUM(AVG_ROW_LENGTH*TABLE_ROWS+INDEX_LENGTH)/1024/1024 AS total_mb FROM information_schema.TABLES group by table_schema; The second case: Check the size of the specified database, for example: database test, the method is as follows: mysql> use information_schema; mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data from TABLES where table_schema='test'; +----------+ | data | +----------+ | 142.84MB | +----------+ 1 row in set (0.00 sec) 1. View the capacity of all databases select table_schema as 'database', sum(table_rows) as 'Number of records', sum(truncate(data_length/1024/1024, 2)) as 'Data capacity (MB)', sum(truncate(index_length/1024/1024, 2)) as 'Index capacity (MB)' from information_schema.tables group by table_schema order by sum(data_length) desc, sum(index_length) desc; 2. View the capacity of all database tables select table_schema as 'database', table_name as 'table name', table_rows as 'number of records', truncate(data_length/1024/1024, 2) as 'Data capacity (MB)', truncate(index_length/1024/1024, 2) as 'Index capacity (MB)' from information_schema.tables order by data_length desc, index_length desc; 3. Check the capacity of the specified database Example: Check the capacity of the MySQL database select table_schema as 'database', sum(table_rows) as 'Number of records', sum(truncate(data_length/1024/1024, 2)) as 'Data capacity (MB)', sum(truncate(index_length/1024/1024, 2)) as 'Index capacity (MB)' from information_schema.tables where table_schema='mysql'; 4. Check the capacity of each table in the specified database Example: Check the capacity of each table in the MySQL database select table_schema as 'database', table_name as 'table name', table_rows as 'number of records', truncate(data_length/1024/1024, 2) as 'Data capacity (MB)', truncate(index_length/1024/1024, 2) as 'Index capacity (MB)' from information_schema.tables where table_schema='mysql' order by data_length desc, index_length desc; Off-topic methods Directly use shell commands to count the size of the mysql data directory (note that only the library is included, not the database log size) Remark: data_length: storage data size data_length/1024/1024: Convert bytes to MB round(sum(data_length/1024/1024),2): round to two decimal places concat(round(sum(data_length/1024/1024),2),'MB') : Add the unit "MB" to the calculation result This is the end of this article about the method and steps of Mysql query database capacity. For more relevant content about Mysql query database capacity, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to solve the problem that Docker container has no vim command
>>: JavaScript parseInt() and Number() difference case study
Each of these 16 sites is worth reading carefully,...
If you want to install some 64-bit applications (...
What is the reason for the Last_IO_Errno:1236 err...
Table of contents Why do databases need indexes? ...
Set Tomcat to automatically start the service: I ...
When MySQL performs DDL operations such as alter ...
Overview Nginx load balancing provides upstream s...
1. The ENV instruction in the Dockerfile is used ...
1 Download MySQL8 from the official website and i...
mysql correctly cleans up binlog logs Preface: Th...
Table of contents Problem description: Solution 1...
CSS3 syntax: (1rem = 100px for a 750px design) @m...
Today I have a question about configuring MySQL d...
Table of contents 10,000 pieces of data were lost...
Pull the image docker pull season/fastdfs:1.2 Sta...