在Linux系統中,我們可以通過一些簡單的命令來查看MySQL數據庫的大小。
$ mysql -u username -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 50354 Server version: 5.5.54-0ubuntu0.14.04.1 (Ubuntu) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use database_name; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> SELECT table_schema AS "Database Name", SUM(data_length + index_length) / 1024 / 1024 AS "Database Size (MB)" FROM information_schema.TABLES GROUP BY table_schema; +--------------------+---------------------+ | Database Name | Database Size (MB) | +--------------------+---------------------+ | database_one | 23.87500000 | | database_two | 0.15625000 | | database_three | 0.23437500 | +--------------------+---------------------+ 3 rows in set (0.24 sec)
在上面的命令中,我們首先輸入了MySQL帳號的用戶名和密碼,并登錄到MySQL的控制臺。然后我們在使用的數據庫名后加入了SELECT語句來查看該數據庫下所有表的大小。
在信息輸出中,我們可以看到數據庫的名稱和大小,以兆字節(MB)為單位。在這個例子中,我們可以看到我們使用的數據庫有三個表,總大小為約24MB。
通過這種方式,我們可以輕松地查看我們在Linux系統上運行的MySQL數據庫的大小。