zoukankan      html  css  js  c++  java
  • Mysql 性能监控及调优

    死锁概念:
    两个或两个以上的进程在执行过程中,因争夺资源而造成的一种互相等待的现象

    1.监控死锁(innotop):

    (1) 启用 innodb_status_file
    在/etc/my.cnf添加如下:

    [mysqld]
    innodb_status_file =1
     于/var/lib/mysql/下查看.err日志

    (2)启用 innodb_monitor
    建立监视表:

    mysql>use mysql;
    mysql> create table innodb_monitor ( id int ) engine = innodb;
    mysql> show innodb statusG;  

    例:一个表test,结构如下:

      id:主键;
      state:状态;
      time:时间;
      索引:index(statetime)

    任务1: update test set state=1064,time=now() where state=1061 and time < date_sub(now(), INTERVAL 30 minute);

    锁分析:先锁定非主键索引index,再锁定主键索引id

    任务2: update test set state=1067,time=now() where id in (9921180);

    锁分析:先锁定主键索引id,再锁定非主键索引index

    解决方法:保证锁顺序一致

    select id from tab_test where state=1061 and time < date_sub(now(), INTERVAL 30 minute);
    update tab_test state=1064,time=now() where id in(......);

    2.监控慢查询操作:

    在/etc/my.cnf添加如下:

    [mysqld]
    slow_query_log=1
    slow_query_log_file=/tmp/mysqld_slow.log
    long-query-time=1(单位:秒)
    log-queries-not-using-indexes(未使用索引)

    这里写图片描述

  • 相关阅读:
    Python编程第5讲—if 语句
    GIT 笔记
    jQuery多余文字折叠效果
    静态库与动态库的制作与使用
    Makefile
    C++ 有理数类
    使用mstest.exe 命令行跑test case(不安装Visual Studio 2010)
    Termp Folder and its subfolders
    ToString() 格式化字符串总结
    REST基础
  • 原文地址:https://www.cnblogs.com/qwop/p/6637383.html
Copyright © 2011-2022 走看看