mysql 查询碎片的方法

mysql 查询碎片的方法

mysql> select table_schema,concat(‘alter table ‘,table_name, ‘ engine=Innodb ;‘),(data_length+index_length)/1024/1024 length,engine,data_free,table_rows from information_schema.tables where table_schema not in (‘information_schema‘,‘mysql‘,‘performance_schema‘)      and data_free !=0 group by table_name order by table_rows asc;
+---------------------+------------------------------------------------------------------+---------------+--------+-----------+------------+
| table_schema        | concat(‘alter table ‘,table_name, ‘ engine=Innodb ;‘)            | length        | engine | data_free | table_rows |
+---------------------+------------------------------------------------------------------+---------------+--------+-----------+------------+
| testdbs_students001 | alter table student_period_history_201705 engine=Innodb ;  |    2.03125000 | InnoDB |   4194304 |       7407 |
| testdbs_students001 | alter table student_period_history_201706 engine=Innodb ;  |    1.51562500 | InnoDB |   4194304 |       7815 |
| testdbs_students001 | alter table transfer_order_record engine=Innodb ;          |    1.82812500 | InnoDB |   4194304 |       8001 |
| testdbs_students001 | alter table teacher_account engine=Innodb ;                |    2.40625000 | InnoDB |   4194304 |       8221 |
| testdbs_students001 | alter table period_appeal_log engine=Innodb ;              |    1.51562500 | InnoDB |   4194304 |       9412 |
| testdbs_students001 | alter table student_period_history_201704 engine=Innodb ;  |    2.23437500 | InnoDB |   4194304 |       9996 |
| testdbs_students001 | alter table student_period_history_201709 engine=Innodb ;  |    1.51562500 | InnoDB |   4194304 |      12011 |
| testdbs_students001 | alter table failed_jobs engine=Innodb ;                    |    8.51562500 | InnoDB |   4194304 |      12595 |
| testdbs_students001 | alter table student_period_history_201707 engine=Innodb ;  |    2.51562500 | InnoDB |   4194304 |      16019 |
| testdbs_students001 | alter table student_course_repair_log engine=Innodb ;      |   50.90625000 | InnoDB |   7340032 |      16955 |
| testdbs_students001 | alter table order_period_warning engine=Innodb ;           |    3.84375000 | InnoDB |   4194304 |      17711 |
| testdbs_students001 | alter table send_msg_log engine=Innodb ;                   |    3.40625000 | InnoDB |   4194304 |      19140 |
| testdbs_students001 | alter table back_period_log engine=Innodb ;                |    2.51562500 | InnoDB |   4194304 |      22785 |
| testdbs_students001 | alter table teacher_finance engine=Innodb ;                |    2.50000000 | InnoDB |   4194304 |      23018 |
| testdbs_students001 | alter table student_period_history_201711 engine=Innodb ;  |    2.51562500 | InnoDB |   4194304 |      23263 |
| testdbs_students001 | alter table student_period_history_201710 engine=Innodb ;  |    2.51562500 | InnoDB |   4194304 |      24336 |
| testdbs_students001 | alter table student_period_cancel_request engine=Innodb ;  |    5.03125000 | InnoDB |   4194304 |      25585 |
| testdbs_students001 | alter table student_period_history_201708 engine=Innodb ;  |    3.51562500 | InnoDB |   4194304 |      29830 |
| testdbs_students001 | alter table student_course_error_log engine=Innodb ;       |   22.06250000 | InnoDB |   4194304 |      31661 |
| testdbs_students001 | alter table order_paymenttype_changed_logs engine=Innodb ; |    5.50000000 | InnoDB |   4194304 |      33330 |
| testdbs_students001 | alter table student_period_history_201801 engine=Innodb ;  |    4.51562500 | InnoDB |   4194304 |      40481 |
| testdbs_students001 | alter table student_period_history_201712 engine=Innodb ;  |    4.51562500 | InnoDB |   4194304 |      41839 |
| testdbs_students001 | alter table teacher_teaching_award_list engine=Innodb ;    |    6.54687500 | InnoDB |   4194304 |      45883 |
| testdbs_students001 | alter table teacher_base_finance_log engine=Innodb ;       |   13.57812500 | InnoDB |   4194304 |      56640 |
| testdbs_students001 | alter table student_period_history_201802 engine=Innodb ;  |    6.51562500 | InnoDB |   4194304 |      59748 |
| testdbs_students001 | alter table withdraw engine=Innodb ;                       |   23.54687500 | InnoDB |   4194304 |      61167 |
| testdbs_students001 | alter table student_period_history_201803 engine=Innodb ;  |    7.51562500 | InnoDB |   3145728 |      69367 |
| testdbs_students001 | alter table teacher_student_period engine=Innodb ;         |    8.03125000 | InnoDB |   4194304 |      74849 |
| testdbs_students001 | alter table student_period_history_201804 engine=Innodb ;  |    8.51562500 | InnoDB |   4194304 |      80023 |
| testdbs_students001 | alter table student_period_history_201805 engine=Innodb ;  |    8.51562500 | InnoDB |   4194304 |      83745 |
| testdbs_students001 | alter table student_course engine=Innodb ;                 |   11.03125000 | InnoDB |   4194304 |      90741 |
| testdbs_students001 | alter table student_period_history_201809 engine=Innodb ;  |    9.51562500 | InnoDB |   4194304 |      92332 |
| testdbs_students001 | alter table student_period_history_201806 engine=Innodb ;  |    9.51562500 | InnoDB |   4194304 |      94333 |
| testdbs_students001 | alter table order_credit_info engine=Innodb ;              |   45.07812500 | InnoDB |   7340032 |      97368 |
| testdbs_students001 | alter table student_period_history_201810 engine=Innodb ;  |   15.51562500 | InnoDB |   4194304 |     155869 |
| testdbs_students001 | alter table student_period_history_201807 engine=Innodb ;  |   15.51562500 | InnoDB |   4194304 |     156100 |
| testdbs_students001 | alter table student_period_history_201811 engine=Innodb ;  |   16.51562500 | InnoDB |   4194304 |     159868 |
| testdbs_students001 | alter table student_period_history_201905 engine=Innodb ;  |   17.51562500 | InnoDB |   4194304 |     170079 |
| testdbs_students001 | alter table student_period_history_201902 engine=Innodb ;  |   17.51562500 | InnoDB |   4194304 |     175909 |
| testdbs_students001 | alter table order_period_warning_info engine=Innodb ;      |   24.54687500 | InnoDB |   6291456 |     178991 |
| testdbs_students001 | alter table student_period_history_201812 engine=Innodb ;  |   19.54687500 | InnoDB |   4194304 |     194860 |
| testdbs_students001 | alter table student_period_history_201808 engine=Innodb ;  |   20.54687500 | InnoDB |   4194304 |     203676 |
| testdbs_students001 | alter table student_period_history_201904 engine=Innodb ;  |   20.54687500 | InnoDB |   4194304 |     204831 |
| testdbs_students001 | alter table student_period_history_201903 engine=Innodb ;  |   21.54687500 | InnoDB |   3145728 |     218756 |
| testdbs_students001 | alter table student_period_history_201901 engine=Innodb ;  |   22.54687500 | InnoDB |   4194304 |     219717 |
| testdbs_students001 | alter table student_finance engine=Innodb ;                |   28.54687500 | InnoDB |   7340032 |     368189 |
| testdbs_students001 | alter table course_real_period_log engine=Innodb ;         |   79.03125000 | InnoDB |   5242880 |     404931 |
| testdbs_students001 | alter table course_real_period engine=Innodb ;             |   71.04687500 | InnoDB |   5242880 |     406539 |
| testdbs_students001 | alter table audition_order engine=Innodb ;                 |  179.03125000 | InnoDB |   7340032 |     548999 |
| testdbs_students001 | alter table inform_order engine=Innodb ;                   |  429.85937500 | InnoDB |   7340032 |     648426 |
| testdbs_students001 | alter table teacher_full_time_finance_log engine=Innodb ;  |  136.79687500 | InnoDB |   7340032 |     700182 |
| testdbs_students001 | alter table teacher_all_time_finance_log engine=Innodb ;   |  137.79687500 | InnoDB |   4194304 |     712279 |
| testdbs_students001 | alter table student_period_cancel_logs engine=Innodb ;     |   90.14062500 | InnoDB |   4194304 |     841515 |
| testdbs_students001 | alter table course_order engine=Innodb ;                   |  377.00000000 | InnoDB |   6291456 |    1113689 |
| testdbs_students001 | alter table order engine=Innodb ;                          |  547.34375000 | InnoDB |   7340032 |    1121134 |
| testdbs_students001 | alter table order_status_log engine=Innodb ;               |  137.28125000 | InnoDB |   5242880 |    1182890 |
| testdbs_students001 | alter table student_finance_log engine=Innodb ;            |  171.21875000 | InnoDB |   5242880 |    1349596 |
| testdbs_students001 | alter table uid_to_sale engine=Innodb ;                    |  122.98437500 | InnoDB |   6291456 |    1480265 |
| testdbs_students001 | alter table period_msg_to_teacher engine=Innodb ;          |  424.75000000 | InnoDB |   6291456 |    2183860 |
| testdbs_students001 | alter table teacher_course_remark engine=Innodb ;          | 2983.00000000 | InnoDB |   4194304 |    2226556 |
| testdbs_students001 | alter table student_period engine=Innodb ;                 |  386.21875000 | InnoDB |   6291456 |    2344035 |
| testdbs_students001 | alter table teacher_part_time_finance_log engine=Innodb ;  |  645.54687500 | InnoDB |   7340032 |    3224173 |
| testdbs_students001 | alter table teacher_subsidy_detail engine=Innodb ;         |  827.20312500 | InnoDB |   6291456 |    3812535 |
| testdbs_students001 | alter table student_course_log engine=Innodb ;             |  816.54687500 | InnoDB |   4194304 |    4489196 |
| testdbs_students001 | alter table teacher_finance_log engine=Innodb ;            | 1449.75000000 | InnoDB |   5242880 |    6493046 |
| testdbs_students001 | alter table order_update_log engine=Innodb ;               | 1088.00000000 | InnoDB |   7340032 |    7501555 |
+---------------------+------------------------------------------------------------------+---------------+--------+-----------+------------+
66 rows in set (0.02 sec)

mysql> 

原文地址:https://www.cnblogs.com/bjx2020/p/10981267.html

时间: 2024-10-12 04:33:21

mysql 查询碎片的方法的相关文章

MySql查询时间段的方法

本文实例讲述了MySql查询时间段的方法.分享给大家供大家参考.具体方法如下: MySql查询时间段的方法未必人人都会,下面为您介绍两种MySql查询时间段的方法,供大家参考. MySql的时间字段有date.time.datetime.timestamp等,往往我们在存储数据的时候将整个时间存在一个字段中,采用datetime类型:也可能采用将日期和时间分离,即一个字段存储date,一个字段存储时间time.无论怎么存储,在实际应用中,很可能会出现包含"时间段"类型的查询,比如一个访

mysql查询乱码解决方法

http://blog.csdn.net/u012408083/article/details/52734762 MySQL 命令行查询乱码 编码问题 当使用数据库工具查询数据时显示数据正常,中文也很正常,利用命令查询时,中文显示乱码 查看数据库状态: mysql> status; 发现客户端Client及连接Conn. characterset 均为utf8,说明是客户端显示有问题,因为mysql的客户端无法以utf-8的形式返回数据,设置客户端显示格式即可: mysql> set name

Mysql查询缓存碎片、缓存命中率及Nagios监控

Mysql 的优化方案,在互联网上可以查找到非常多资料,今天对Mysql缓存碎片和命中率作了详细了解,个人作了简单整理. 一.Mysql查询缓存碎片和缓存命中率. mysql> SHOW STATUS LIKE 'qcache%'; +-------------------------+-----------+ | Variable_name | Value | +-------------------------+-----------+ | Qcache_free_blocks | 5 |

MySQL处理海量数据使得一些优化查询速度的方法

由于在参与的实际项目中发现当mysql表的数据量达到百万级时,普通SQL查询效率呈直线下降,而且如果where中的查询条件较多时,其查询速度简直无法容忍.曾经测试对一个包含400多万条记录(有索引)的表执行一条条件查询,其查询时间竟然高达40几秒,相信这么高的查询延时,任何用户都会抓狂.因此如何提高sql语句查询效率,显得十分重要.以下是网上流传比较广泛的30种SQL查询语句优化方法: 1.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询

mysql查询今天,昨天,近7天,近30天,本月,上一月数据的方法(摘录)

mysql查询今天,昨天,近7天,近30天,本月,上一月数据的方法分析总结: 话说有一文章表article,存储文章的添加文章的时间是add_time字段,该字段为int(5)类型的,现需要查询今天添加的文章总数并且按照时间从大到小排序,则查询语句如下: select * from `article` where date_format(from_UNIXTIME(`add_time`),'%Y-%m-%d') = date_format(now(),'%Y-%m-%d'); 或者: selec

板邓:mysql查询今天,昨天,近7天,近30天,本月,上一月数据的方法

mysql查询今天,昨天,近7天,近30天,本月,上一月数据的方法分析总结: 话说有一文章表article,存储文章的添加文章的时间是add_time字段,该字段为int(5)类型的,现需要查询今天添加的文章总数并且按照时间从大到小排序,则查询语句如下: select * from `article` where date_format(from_UNIXTIME(`add_time`),’%Y-%m-%d’) = date_format(now(),’%Y-%m-%d’); 或者: selec

Mysql 查询缓存利弊

Mysql 查询缓存总结 MySQL查询缓存解释 缓存完整的SELECT查询结果,也就是查询缓存.保存查询返回的完整结果.当查询命中该缓存,mysql会立刻返回结果,跳过了解析.优化和执行阶段, 查询缓存系统会跟踪查询中涉及的每个表,如果这些表发生变化,那么和这个表相关的所有数据都将失效 命中条件 Mysql判断缓存命中的方法很简单:缓存存放在一个引用表中,通过一个哈希值引用,这个哈希值包括如下因素,即查询本身.当前要查询的数据库.客户端协议的版本等一些都有可能影响返回结果信息. 当判断查询缓存

生产要不要开启MySQL查询缓存

一.前言在当今的各种系统中,缓存是对系统性能优化的重要手段.MySQL Query Cache(MySQL查询缓存)在MySQL Server中是默认打开的,但是网上各种资料以及有经验的DBA都建议生产环境中把MySQL Query Cache关闭.按道理,MySQL Server默认打开,是鼓励用户使用缓存,但是大拿们却建议关闭此功能,并且国内各个云厂商提供的MySQL云服务中默认都是关闭这个功能,这是为什么?他们在使用中遇到了什么坑?本文将会从以下几方面来详解MySQL Query Cach

MySQL 查询语句使用进阶

MySQL 查询语句使用进阶 =============================================================================== 概述: =============================================================================== 练习: 练习1  首先导入hellodb.sql的脚本文件,查询其数据库和表如下: [[email protected] ~]# mysql