zoukankan      html  css  js  c++  java
  • mysql数据库运行性能检查脚本

    只针对mysql 5.6.8以上版本
    select version();
    use information_schema;
    #查询所有数据库参数
    show VARIABLES;

    #查询数据库最大连接数
    show variables like '%max_connections%';

    #查询当前数据库连接数
    show full processlist;

    #单表记录数超过1000W的数据库查询
    select table_schema,table_name,table_rows
    from information_schema.tables where table_rows >=10000000 ;

    #查看数据库所有索引
    SELECT * FROM mysql.`innodb_index_stats` a WHERE a.`database_name` = 'uum';

    #查看某一表索引
    SELECT * FROM mysql.`innodb_index_stats` a WHERE a.`database_name` = 'uum' and a.table_name like '%t_sys_base_user%';
    SELECT * FROM mysql.`innodb_index_stats` a WHERE a.`database_name` = 'uum' and a.table_name ='t_sys_base_user';

    #数据库表空间大于1T检查
    SELECT table_schema as 'Database',
           table_name,
        CONCAT(ROUND(data_length/(1024*1024*1024),6),' G') AS 'Data Size',   
        CONCAT(ROUND(index_length/(1024*1024*1024),6),' G') AS 'Index Size' ,   
        CONCAT(ROUND((data_length+index_length)/(1024*1024*1024),6),' G') AS'Total'  
    FROM information_schema.TABLES;

    #数据文件存放路径
    show variables like 'datadir';

    #数据库文件占用磁盘空间检查
    du -h /data/mysql/data/

    #告警 mysql错误日志存放路径
    show variables where variable_name = 'log_error';


    #mysql数据库监控:
    #慢查询日志
    show variables WHERE  variable_name = 'slow_query_log_file';
     
    #查询写入慢查询日志的时间阈值
    show variables WHERE  variable_name = 'long_query_time';
     
    #查询哪个sql消耗资源情况
    select Id,User,Host,db,Time,Info from information_schema.`PROCESSLIST` where info is not null;

    #查询是否锁表
    show OPEN TABLES where In_use > 0;

    #查看正在等待锁的事务
    SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;

    #查询所有数据的大小
    select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;

    #查看指定数据库的大小
    select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='uum';

    #查看指定数据库的某个表的大小
    select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='uum' and table_name='t_sys_base_user';


    Linux下命令:free –m    系统实际内存
    •used=total-free 即 total=used+free
    •实际内存占用:used-buffers-cached 即 total-free-buffers-cached
    •实际可用内存:buffers+cached+free
    •total 内存总数: 128
    •used 已经使用的内存数: 119
    •free 空闲的内存数: 8
    •shared 当前已经废弃不用,总是0
    •buffers Buffer Cache内存数: 1
    •cached Page Cache内存数: 22
    •-buffers/cache 的内存数:95 (等于第1行的 used - buffers - cached)
    •+buffers/cache 的内存数: 32 (等于第1行的 free + buffers + cached)
    •SWAP 虚拟内存

    Linux下命令:iostat 1 1   IO使用情况
    avg-cpu: 总体cpu使用情况统计信息,对于多核cpu,这里为所有cpu的平均值
    Device: 各磁盘设备的IO统计信息
    Device: 以sdX形式显示的设备名称
    •tps: 每秒进程下发的IO读、写请求数量
    •KB_read/s: 每秒读扇区数量(一扇区为512bytes)
    •KB_wrtn/s: 每秒写扇区数量
    •KB_read: 取样时间间隔内读扇区总数量
    •KB_wrtn: 取样时间间隔内写扇区总数量

    Linux下命令:vmstat 2 2000    虚拟内存
    Procs(进程):
    r: 运行队列中进程数量
    b: 等待IO的进程数量
    Memory(内存):
    swpd: 使用虚拟内存大小
    free: 可用内存大小
    buff: 用作缓冲的内存大小
    cache: 用作缓存的内存大小
    Swap:
    si: 每秒从交换区写到内存的大小
    so: 每秒写入交换区的内存大小
    IO:(现在的Linux版本块的大小为1024bytes)
    bi: 每秒读取的块数
    bo: 每秒写入的块数
     系统:
    in: 每秒中断数,包括时钟中断。
    cs: 每秒上下文切换数。
    CPU(以百分比表示):
    us: 用户进程执行时间(user time)
    sy: 系统进程执行时间(system time)
    id: 空闲时间(包括IO等待时间)
    wa: 等待IO时间
       
    Linux下  命令:top      cpu使用情况   
    PID — 进程id
    USER — 进程所有者
    PR — 进程优先级
    NI — nice值。负值表示高优先级,正值表示低优先级
    VIRT — 进程使用的虚拟内存总量,单位kb。VIRT=SWAP+RES
    RES — 进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA
    SHR — 共享内存大小,单位kb
    S — 进程状态。D=不可中断的睡眠状态 R=运行 S=睡眠 T=跟踪/停止 Z=僵尸进程
    %CPU — 上次更新到现在的CPU时间占用百分比
    %MEM — 进程使用的物理内存百分比
    TIME+ — 进程使用的CPU时间总计,单位1/100秒
    COMMAND — 进程名称(命令名/命令行)

    # 检查mysql数据库各个表空间的大小(数据空间和索引空间以及总和)
        select TABLE_NAME,
                concat(truncate(data_length/1024/1024/1024, 2), 'GB') as data_size,
                concat(truncate(index_length /1024/1024/1024, 2), 'GB') as index_size,
                truncate(data_length/1024/1024/1024, 2)+  truncate(index_length /1024/1024/1024, 2)
        from information_schema.tables where TABLE_SCHEMA = 'smapuum'  order by data_length desc;








  • 相关阅读:
    19.递归法和非递归法反转链表[ReverseLinkedList]
    18.用两个栈实现队列[2StacksToImplementQueue]
    17.把字符串转换成整数[atoi]
    16.O(logn)求Fibonacci数列[Fibonacci]
    15.含有指针成员的类的拷贝[ClassCopyConstructorWithPointerMember]
    14.约瑟夫环问题[JosephusProblem]
    13.第一个只出现一次的字符[FindFirstNotRepeatingChar]
    12.从上往下遍历二元树[LevelOrderOfBinaryTree]
    洛谷 P2919 [USACO08NOV]守护农场Guarding the Farm
    洛谷 P2733 家的范围 Home on the Range
  • 原文地址:https://www.cnblogs.com/pdspkj/p/10082294.html
Copyright © 2011-2022 走看看