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
brew install nginx Apple Mac uses brew to install...
What are slots? The slot directive is v-slot, whi...
Preface Recently, due to work needs, I need to in...
Table of contents First we need to build the page...
The color presentation on a web page will be affec...
Because of network isolation, MySQL cannot be ins...
Preface: When passing data between parent and chi...
Table of contents 1. Routing related objects 2. L...
Description of the phenomenon: The project uses s...
The Explain command is the first recommended comm...
var numA = 0.1; var numB = 0.2; alert( numA + num...
Table of contents 1. Delete the old version 2. Ch...
The commonly used Oracle10g partitions are: range...
<br />I just saw the newly revamped ChinaUI....
1. Install the cross-system file transfer tool un...