当前位置:Gxlcms > mysql > mysql常用监控脚本整理_MySQL

mysql常用监控脚本整理_MySQL

时间:2021-07-01 10:21:17 帮助过:16人阅读

bitsCN.com

mysql常用监控脚本整理

01#!/bin/sh02#filename:mysql_monitor.sh03#site:www.jbxue.com04#检测mysql server是否正常提供服务05mysqladmin -u sky -ppwd -h localhost ping0607#获取mysql当前的几个状态值08mysqladmin -u sky -ppwd -h localhost status0910#获取数据库当前的连接信息11mysqladmin -u sky -ppwd -h localhost processlist1213#获取当前数据库的连接数14mysql -u root -p123456 -BNe "select host,count(host) from processlist group by host;" information_schema1516#显示mysql的uptime17mysql -e"SHOW STATUS LIKE '%uptime%'"|awk '/ptime/{ calc = $NF / 3600;print $(NF-1), calc"Hour" }'1819#查看数据库的大小20mysql -u root -p123456-e 'select table_schema,round(sum(data_length+index_length)/1024/1024,4) from information_schema.tables group by table_schema;'2122#查看某个表的列信息23mysql -u  --password= -e "SHOW COLUMNS FROM "  | awk '{print $1}' | tr "/n" "," | sed 's/,$//g'2425#执行mysql脚本26mysql -u user-name -p password < script.sql2728#mysql dump数据导出29mysqldump -uroot -T/tmp/mysqldump test test_outfile --fields-enclosed-by=/" --fields-terminated-by=,3031#mysql数据导入32mysqlimport --user=name --password=pwd test --fields-enclosed-by=/" --fields-terminated-by=, /tmp/test_outfile.txt33LOAD DATA INFILE '/tmp/test_outfile.txt' INTO TABLE test_outfile FIELDS TERMINATED BY '"' ENCLOSED BY ',';343536#mysql进程监控37ps -ef | grep "mysqld_safe" | grep -v "grep"38ps -ef | grep "mysqld" | grep -v "mysqld_safe"| grep -v "grep"3940#查看当前数据库的状态41mysql -u root -p123456 -e 'show status'4243#mysqlcheck 工具程序可以检查(check),修 复( repair),分 析( analyze)和优化(optimize)MySQL Server 中的表44mysqlcheck -u root -p123456 --all-databases4546#mysql qps查询  QPS = Questions(or Queries) / Seconds47mysql -u root -p123456 -e 'SHOW /*!50000 GLOBAL */ STATUS LIKE "Questions"'48mysql -u root -p123456 -e 'SHOW /*!50000 GLOBAL */ STATUS LIKE "Queries"'49#mysql Key Buffer 命中率  key_buffer_read_hits = (1 - Key_reads / Key_read_requests) * 100%  key_buffer_write_hits= (1 - Key_writes / Key_write_requests) * 100%50mysql -u root -p123456 -e 'SHOW /*!50000 GLOBAL */ STATUS LIKE "Key%"'5152#mysql Innodb Buffer 命中率  innodb_buffer_read_hits=(1-Innodb_buffer_pool_reads/Innodb_buffer_pool_read_requests) * 100%53mysql -u root -p123456 -e 'SHOW /*!50000 GLOBAL */ STATUS LIKE "Innodb_buffer_pool_read%"'5455#mysql Query Cache 命中率 Query_cache_hits= (Qcache_hits / (Qcache_hits + Qcache_inserts)) * 100%56mysql -u root -p123456 -e 'SHOW /*!50000 GLOBAL */ STATUS LIKE "Qcache%"'5758#mysql Table Cache 状态量59mysql -u root -p123456 -e 'SHOW /*!50000 GLOBAL */ STATUS LIKE "Open%"'6061#mysql Thread Cache 命中率  Thread_cache_hits = (1 - Threads_created / Connections) * 100%  正常来说,Thread Cache 命中率要在 90% 以上才算比较合理。62mysql -u root -p123456 -e 'SHOW /*!50000 GLOBAL */ STATUS LIKE "Thread%"'63# www.jbxue.com6465#mysql 锁定状态:锁定状态包括表锁和行锁两种,我们可以通过系统状态变量获得锁定总次数,锁定造成其他线程等待的次数,以及锁定等待时间信息66mysql -u root -p123456 -e 'SHOW /*!50000 GLOBAL */ STATUS LIKE "%lock%"'6768#mysql 复制延时量 在slave节点执行69mysql -u root -p123456 -e 'SHOW SLAVE STATUS'7071#mysql Tmp table 状况 Tmp Table 的状况主要是用于监控 MySQL 使用临时表的量是否过多,是否有临时表过大而不得不从内存中换出到磁盘文件上72mysql -u root -p123456 -e 'SHOW /*!50000 GLOBAL */ STATUS LIKE "Created_tmp%"'7374#mysql Binlog Cache 使用状况:Binlog Cache 用于存放还未写入磁盘的 Binlog 信 息 。75mysql -u root -p123456 -e 'SHOW /*!50000 GLOBAL */ STATUS LIKE "Binlog_cache%"'7677#mysql nnodb_log_waits 量:Innodb_log_waits 状态变量直接反应出 Innodb Log Buffer 空间不足造成等待的次数78mysql -u root -p123456 -e 'SHOW /*!50000 GLOBAL */ STATUS LIKE "Innodb_log_waits'

bitsCN.com

人气教程排行