zoukankan      html  css  js  c++  java
  • Mysql优化操作学习纪录

    SHOW STATUS;
    FLUSH STATUS;

    查看当前连接数 SHOW STATUS LIKE 'Thread_%';
    Thread_cached:被缓存的线程的个数
    Thread_running:处于激活状态的线程的个数
    Thread_connected:当前连接的线程的个数
    Thread_created:总共被创建的线程的个数

    Thread cache hits
    Thread_connected = SHOW GLOBAL STATUS LIKE Thread_created;
    Connections = SHOW GLOBAL STATUS LIKE 'Connections';
    TCH=(1 - (Threads_created / Connections)) * 100

    查看活动连接内容
    SHOW PROCESSLIST;

    如果 TCH数小于90%,创建连接耗费了时间,增大Thread_cached数量

    QPS (每秒查询处理量)MyISAM 引擎

    Questions = SHOW GLOBAL STATUS LIKE 'Questions';
    Uptime = SHOW GLOBAL STATUS LIKE 'Uptime';
    QPS=Questions/Uptime

    TPS(每秒传输的事物处理个数),即服务器每秒处理的事务数,如果是InnoDB会显示,没有InnoDB就不会显示。

    Com_commit = SHOW GLOBAL STATUS LIKE 'Com_commit';
    Com_rollback = SHOW GLOBAL STATUS LIKE 'Com_rollback';
    Uptime = SHOW GLOBAL STATUS LIKE 'Uptime';
    TPS=(Com_commit + Com_rollback)/Uptime

    QPS 和 TPS值一定要实时监控,如果接近架构搭建时的测试峰值,愿上帝与你同在

    Read/Writes Ratio
    Qcache_hits = SHOW GLOBAL STATUS LIKE 'Qcache_hits';
    Com_select = SHOW GLOBAL STATUS LIKE 'Com_select';
    Com_insert = SHOW GLOBAL STATUS LIKE 'Com_insert';
    Com_update = SHOW GLOBAL STATUS LIKE 'Com_update';
    Com_delete = SHOW GLOBAL STATUS LIKE 'Com_delete';
    Com_replace = SHOW GLOBAL STATUS LIKE 'Com_replace';
    R/W=(Com_select + Qcache_hits) / (Com_insert + Com_update + Com_delete + Com_replace) * 100

    读写比,优化数据库的重要依据,读的多就去优化读,写的多就去优化写

    Slow queries per minute
    Slow_queries = SHOW GLOBAL STATUS LIKE 'Slow_queries';
    Uptime = SHOW GLOBAL STATUS LIKE 'Uptime';
    SQPM=Slow_queries / (Uptime/60)

    Slow queries /Questions Ratio
    Slow_queries = SHOW GLOBAL STATUS LIKE 'Slow_queries';
    Questions = SHOW GLOBAL STATUS LIKE 'Questions';
    S/Q=Slow_queries/Questions

    新版本上线时要着重关注慢查询,让测试去踢开发者的屁股吧

    Full_join per minute
    Select_full_join = SHOW GLOBAL STATUS LIKE 'Select_full_join';
    Uptime = SHOW GLOBAL STATUS LIKE 'Uptime';
    FJPM=Select_full_join / (Uptime/60)

    没有使用索引而造成的full_join,优化索引去吧

    Innodb buffer read hits
    Innodb_buffer_pool_reads = SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_reads';
    Innodb_buffer_pool_read_requests = SHOW GLOBAL STATUS LIKE 'Innodb_buffer_pool_read_requests';
    IFRH=(1 - Innodb_buffer_pool_reads/Innodb_buffer_pool_read_requests) * 100

    InnoDB Buffer命中率 目标 95%-99%;

    Table Cache
    Open_tables= SHOW GLOBAL STATUS LIKE 'Open_tables';
    Opened_tables= SHOW GLOBAL STATUS LIKE 'Opened_tables';
    table_cache= SHOW GLOBAL STATUS LIKE 'table_cache';

    table_cache应该大于 Open_tables 小于 Opened_tables

    Temp tables to Disk ratio

    Created_tmp_tables = show global status like 'Created_tmp_tables';
    Created_tmp_disk_tables = show global status like 'Created_tmp_disk_tables';

    TDR=(Created_tmp_disk_tables/Created_tmp_tables)*100

    SHOW GLOBAL STATUS LIKE 'Innodb_row_lock_%';

    • Innodb_row_lock_current_waits

      The number of row locks currently being waited for. Added in MySQL 5.0.3.

    • Innodb_row_lock_time

      The total time spent in acquiring row locks, in milliseconds. Added in MySQL 5.0.3.

    • Innodb_row_lock_time_avg

      The average time to acquire a row lock, in milliseconds. Added in MySQL 5.0.3.

    • Innodb_row_lock_time_max

      The maximum time to acquire a row lock, in milliseconds. Added in MySQL 5.0.3.

    • Innodb_row_lock_waits

      The number of times a row lock had to be waited for. Added in MySQL 5.0.3.

    ——————————————————————————————————————————————————

    1.系统mysql的进程数

    ps -ef | grep "mysql" | grep -v "grep" | wc –l

    2.Slave_running

    mysql > show status like 'Slave_running';

    如果系统有一个从复制服务器,这个值指明了从服务器的健康度

    3.Threads_connected

    mysql > show status like 'Threads_connected';

    当前客户端已连接的数量。这个值会少于预设的值,但你也能监视到这个值较大,这可保证客户端是处在活跃状态。

    4.Threads_running

    mysql > show status like 'Threads_running';

    如果数据库超负荷了,你将会得到一个正在(查询的语句持续)增长的数值。这个值也可以少于预先设定的值。这个值在很短的时间内超过限定值是没问题的。当Threads_running值超过预设值时并且该值在5秒内没有回落时, 要同时监视其他的一些值。

    5.Aborted_clients

    mysql > show status like 'Aborted_clients';

    客户端被异常中断的数值,即连接到mysql服务器的客户端没有正常地断开或关闭。对于一些应用程序是没有影响的,但对于另一些应用程序可能你要跟踪该值,因为异常中断连接可能表明了一些应用程序有问题。

    6.Questions

    mysql> show status like 'Questions';

    每秒钟获得的查询数量,也可以是全部查询的数量,根据你输入不同的命令会得到你想要的不同的值。

    7.Handler_*

    mysql> show status like 'Handler_%';

    如果你想监视底层(low-level)数据库负载,这些值是值得去跟踪的。

    如果Handler_read_rnd_next值相对于你认为是正常值相差悬殊,可能会告诉你需要优化或索引出问题了。Handler_rollback表明事务被回滚的查询数量。你可能想调查一下原因。

    8.Opened_tables

    mysql> show status like 'Opened_tables';

    表缓存没有命中的数量。如果该值很大,你可能需要增加table_cache的数值。典型地,你可能想要这个值每秒打开的表数量少于1或2。

    9.Select_full_join

    mysql> show status like 'Select_full_join';

    没有主键(key)联合(Join)的执行。该值可能是零。这是捕获开发错误的好方法,因为一些这样的查询可能降低系统的性能。

    10.Select_scan

    mysql> show status like 'Select_scan';

    执行全表搜索查询的数量。在某些情况下是没问题的,但占总查询数量该比值应该是常量(即Select_scan/总查询数量商应该是常数)。如果你发现该值持续增长,说明需要优化,缺乏必要的索引或其他问题。

    11.Slow_queries

    mysql> show status like 'Slow_queries';

    超过该值(--long-query-time)的查询数量,或没有使用索引查询数量。对于全部查询会有小的冲突。如果该值增长,表明系统有性能问题。

    12.Threads_created

    mysql> show status like 'Threads_created';

    该值应该是低的。较高的值可能意味着你需要增加thread_cache的数值,或你遇到了持续增加的连接,表明了潜在的问题。

    13.客户端连接进程数

    shell> mysqladmin processlist

    mysql> show processlist;

    你可以通过使用其他的统计信息得到已连接线程数量和正在运行线程的数量,检查正在运行的查询花了多长时间是一个好主意。如果有一些长时间的查询,管理员可以被通知。你可能也想了解多少个查询是在"Locked"的状态—---该值作为正在运行的查询不被计算在内而是作为非活跃的。一个用户正在等待一个数据库响应。

    14.innodb状态

    mysql> show innodb status;

    该语句产生很多信息,从中你可以得到你感兴趣的。首先你要检查的就是“从最近的XX秒计算出来的每秒的平均负载”。

    (1)Pending normal aio reads: 该值是innodb io请求查询的大小(size)。如果该值大到超过了10—20,你可能有一些瓶颈。

    (2)reads/s, avg bytes/read, writes/s, fsyncs/s:这些值是io统计。对于reads/writes大值意味着io子系统正在被装载。适当的值取决于你系统的配置。

    (3)Buffer pool hit rate:这个命中率非常依赖于你的应用程序。当你觉得有问题时请检查你的命中率

    (4)inserts/s, updates/s, deletes/s, reads/s:有一些Innodb的底层操作。你可以用这些值检查你的负载情况查看是否是期待的数值范围。

    15.主机性能状态

    shell> uptime

    16.CPU使用率

    shell> top

    shell> vmstat

    17.磁盘IO

    shell> vmstat

    shell> iostat

    18.swap进出量(内存)

    shell> free

    19.MySQL错误日志

    在服务器正常完成初始化后,什么都不会写到错误日志中,因此任何在该日志中的信息都要引起管理员的注意。
    20.InnoDB表空间信息

    InnoDB仅有的危险情况就是表空间填满----日志不会填满。检查的最好方式就是:show table status;你可以用任何InnoDB表来监视InnoDB表的剩余空间。

    21.QPS每秒Query量

    QPS = Questions(or Queries) / seconds

    mysql > show /* global */ status like 'Question';

    22.TPS(每秒事务量)

    TPS = (Com_commit + Com_rollback) / seconds

    mysql > show status like 'Com_commit';

    mysql > show status like 'Com_rollback';

    23.key Buffer 命中率

    key_buffer_read_hits = (1-key_reads / key_read_requests) * 100%

    key_buffer_write_hits = (1-key_writes / key_write_requests) * 100%

    mysql> show status like 'Key%';

    24.InnoDB Buffer命中率

    Innodb_buffer_read_hits = (1 - innodb_buffer_pool_reads / innodb_buffer_pool_read_requests) * 100%

    mysql> show status like 'innodb_buffer_pool_read%';

    25.Query Cache命中率

    Query_cache_hits = (Qcahce_hits / (Qcache_hits + Qcache_inserts )) * 100%;

    mysql> show status like 'Qcache%';

    26.Table Cache状态量

    mysql> show status like 'open%';

    27.Thread Cache 命中率

    Thread_cache_hits = (1 - Threads_created / connections ) * 100%

    mysql> show status like 'Thread%';

    mysql> show status like 'Connections';

    28.锁定状态

    mysql> show status like '%lock%';

    29.复制延时量

    mysql > show slave status

    30.Tmp Table状况(临时表状况)

    mysql > show status like 'Create_tmp%';

    31.Binlog Cache使用状况

    mysql > show status like 'Binlog_cache%';

    32.Innodb_log_waits量

    mysql > show status like 'innodb_log_waits';

    关注公众号:java宝典
    a

  • 相关阅读:
    常用资料管理
    IIC学习笔记
    博客的开始
    试用Markdown编辑器
    裁剪方法--layer.makesToBounds 和 clipsToBounds区别和联系
    block循环引用问题--内存泄露
    UITextFiled/UITextView---占位文字的设置
    使用KVC取得私有成员变量时报连线错误
    Xcode开发--运行时runtime
    Xcode开发--屏蔽警告
  • 原文地址:https://www.cnblogs.com/java-bible/p/14340722.html
Copyright © 2011-2022 走看看