淘先锋技术网

首页 1 2 3 4 5 6 7

在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数据库的大小。