查询MySql表空间大小

博客介绍了因MySQL表相关信息存于表空间,查询表空间大小需查对应表数据。还提及了查询整个库所有表信息、所有表大小以及该库某个表大小的内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于MySql表的相关信息都存放在information_schema 表空间下面的tables里面,所以查询表空间大小的时候也是查这个表里面的数据.

查询整个库里面所有表的信息

select * from information_schema.tables 
where table_schema='你要查询的库';

查询整个库里面所有表的大小

select table_name,table_rows,data_length+index_length,
concat(round((data_length+index_length)/1024/1024,2),'MB') 
data from information_schema.tables where table_schema='你要查询的库'

查询该库某个表的大小

select table_name,table_rows,data_length+index_length,
concat(round((data_length+index_length)/1024/1024,2),'MB')
 data from information_schema.tables where table_schema='你要查询的库' 
 and table_name='你要查询的表';

} } } else { cout << "用户名或密码错误,请重新输入!" << endl; } break; 查询 MySQL 表空间大小的 SQL 语句: ``` SELECT table_schema AS `Database`, table_name AS `Table`, } case 2: { // 顾客 int subChoice; while (true) { cout << round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB` FROM "欢迎,顾客!" << endl; cout << "1. 查看菜单" << endl; cout << "2 information_schema.TABLES ORDER BY (data_length + index_length) DESC; ``` 调整 MySQL 表空间大小的 SQL 语. 下单" << endl; cout << "3. 查看订单历史记录" << endl; cout << "4.句: 1. 增加表空间大小: ``` ALTER TABLE table_name ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE 退出登录" << endl; cout << "请选择: "; cin >> subChoice; switch (subChoice) { =8; ``` 其中,table_name 是需要调整表空间大小的表名。 2. 减少表空间大小 case 1: { string sql = "SELECT * FROM menu"; MYSQL_RES *result = NULL; MYSQL_ROW row; : MySQL 不支持直接减少表空间大小的操作,但可以通过以下步骤实现: - 备份数据 if (mysql_query(&mysql, sql.c_str())) { cout << "查询菜单失败: " << mysql_error(&mysql; - 删除表; - 重新创建表并导入数据; - 对表进行优化。 例如: ``` CREATE TABLE new) << endl; } else { result = mysql_store_result(&mysql); if (result) { cout << "菜_table LIKE old_table; INSERT INTO new_table SELECT * FROM old_table; ALTER TABLE new_table ENGINE=InnoDB ROW_FORMAT=COMPRESSED KEY品编号\t菜品名称\t菜品价格\t菜品描述" << endl; while ((row = mysql_fetch_row(result)))_BLOCK_SIZE=8; ANALYZE TABLE new_table; RENAME TABLE old_table TO old_table_backup, new_table TO old_table; { cout << row[0] << "\t\t" << row[1] << "\t\t" << row[2] <<DROP TABLE old_table_backup; ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿★永

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值