mysql怎么查询大小
时间 : 2023-07-28 15:57:02声明: : 文章内容来自网络,不保证准确性,请自行甄别信息有效性

要查询MySQL数据库中的表大小,可以使用以下方法:

1. 查询单个表大小:

```sql

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'

AND table_name = 'your_table_name';

```

替换`your_database_name`为你的数据库名称,`your_table_name`为你要查询的表名称。

2. 查询所有表大小:

```sql

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';

```

替换`your_database_name`为你的数据库名称。

3. 查询整个数据库大小:

```sql

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;

```

这将返回每个数据库的总大小。

注意:以上查询结果的大小单位是MB。如果需要以GB或其他单位显示,请相应地调整查询语句。

希望以上方法对你有所帮助!