查看數據庫中表、索引和碎片大小的大小:
select round(sum(data_length/1024/1024),2) as data_length_MB,
round(sum(index_length/1024/1024),2) as index_length_MB ,
round(sum(data_free/1024/1024),2) as index_length_MB ,table_name
from information_schema.tables where table_schema= 'db_oms4_im' group by table_name order by 3 desc;
更具查詢的結果進行整理。
查看錶的碎片情況:DATA_FREE
show TABLE status like 't_app_user';
或者查看:
select * from information_schema.tables where table_schema= 't_app_user';
生成批量腳本:
select CONCAT('alter table ',table_name , ' ENGINE=INNODB;') from information_schema.tables where TABLE_SCHEMA = 'db_chunqiu' and table_name like 't_app_user_head_%';
進行碎片整理:
alter table t_app_user ENGINE=INNODB;
整理前:
mysql> show TABLE status like 't_app_user'\G;
*************************** 1. row ***************************
Name: st_order_cal_record
Engine: InnoDB
Version: 10
Row_format: Dynamic
Rows: 3033960
Avg_row_length: 7117
Data_length: 21594390528
Max_data_length: 0
Index_length: 0
Data_free: 201046622208 --200G碎片左右
Auto_increment: 241541550
Create_time: 2018-05-04 16:17:26
Update_time: 2018-10-12 15:11:18
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
ERROR:
No query specified
整理後:
mysql> show TABLE status like 't_app_user'\G;
*************************** 1. row ***************************
Name: st_order_cal_record
Engine: InnoDB
Version: 10
Row_format: Dynamic
Rows: 3292968
Avg_row_length: 2038
Data_length: 6711918592
Max_data_length: 0
Index_length: 0
Data_free: 4194304 --4M左右
Auto_increment: 241583900
Create_time: 2018-10-12 15:14:30
Update_time: 2018-10-12 15:57:51
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)
ERROR:
No query specified
mysql 表碎片整理
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
MySQL数据库集群-PXC方案
wy53780
2020-04-23 13:55:07
sql語法、關係建模
死瘦宅
2019-02-24 22:35:22
MySQL 事務、函數、觸發器、數據庫備份、權限管理
死瘦宅
2019-02-24 22:35:12
《從0到1學習Flink》—— Flink 讀取 Kafka 數據批量寫入到 MySQL
zhisheng
2019-02-24 21:04:11
SpringBoot 填坑 (一) | CentOS7.4 環境下,表時間字段默認值設置失效
一個優秀的廢人
2019-02-24 15:33:55
mysql-存儲過程
雙子城
2019-02-24 13:43:57
jmeter學習指南之操作 mysql 數據庫
小強測試
2019-02-24 13:34:06
20190222全天的實驗
清歡難尋
2019-02-24 13:17:21
數據庫監控:zabbix(fpmmm)
AMGYM
2019-02-24 13:05:14
數據庫監控:nagios(check_mysql_health)
AMGYM
2019-02-24 13:05:14
如何釋放已刪除的InnoDB磁盤空間
lvrenX
2019-02-24 13:04:33
MYSQL中視圖的使用
雙子城
2019-02-24 08:44:17
MySQL從刪庫到跑路
司木
2019-02-24 00:24:07
JavaBean操作
yi_sixian
2019-02-23 14:05:20
fdb2b技術博客簡介
fdb2b
2019-02-23 14:01:03