python
bitsCN.com #原shell版

1 #!/bin/bash 2 3 # Script Name: mysql_status_check.sh 4 # Description: check mysql servers status 5 # Author: Xinggang Wang - OpsEye.com 6 # Create Date: 2012/3/30 7 8 #获取MySQL所在服务器IP/端口/用户名/密码 9 read -p "Host=" HOST 10 read -p "Port=" PORT 11 read -p "User=" USER 12 read -sp "Password=" PASSWORD 13 echo 14 15 #默认为127.0.0.1/3306/root 16 if [ "${HOST}" = "" ] 17 then 18 HOST='127.0.0.1' 19 fi 20 21 if [ "${PORT}" = "" ] 22 then 23 PORT='3306' 24 fi 25 26 if [ "${USER}" = "" ] 27 then 28 USER='root' 29 fi 30 31 #注意密码为空的时候的格式 32 mysql_list=" 33 $HOST:$PORT:$USER:$PASSWORD 34 " 35 #计算函数,提高脚本效率 36 compute(){ 37 formula="$1" 38 awk 'BEGIN{printf("%.2f",'$formula')}' 2>/dev/null && 39 echo $value || echo NULL 40 } 41 42 for mysql in $mysql_list 43 { 44 host=${mysql%%:*} 45 port=$(echo $mysql|awk -F: '{print $2}') 46 user=$(echo $mysql|awk -F: '{print $3}') 47 passwd=${mysql##*:} 48 49 [ -z "$passwd" ] && mysql="mysql -h$host -P$port -u$user" || 50 mysql="mysql -h$host -P$port -u$user -p$passwd" 51 52 unset Uptime 53 # 把show global status的值赋给相应的参数名称(这里相当于大量的变量赋值操作) 54 eval $( $mysql -e "show global status" | awk '{print $1"=/x27"$2"/047"}') 55 [ X = X"$Uptime" ] && continue 56 57 # Mysql VER 58 VER=`$mysql -e"status;"|grep 'Server version'|awk '{print $3}'` 59 60 # Uptime 61 UPTIME=`compute "$Uptime/3600/24"` 62 63 # Threads_connected 64 threads_connected=`compute "$Threads_connected"` 65 66 # QPS Questions/Uptime 67 qps=`compute "$Questions/$Uptime"` 68 69 # TPS (Com_commit + Com_rollback)/Uptime 70 tps=`compute "($Com_commit+$Com_rollback)/$Uptime"` 71 72 # Reads Com_select + Qcache_hits 73 reads=`compute "$Com_select+$Qcache_hits"` 74 75 # Writes Com_insert + Com_update + Com_delete + Com_replace 76 writes=`compute "$Com_insert+$Com_update+$Com_delete+$Com_replace"` 77 78 # Read/Writes Ratio reads/writes*100% 79 rwratio=`compute "$reads/$writes*100"`% 80 81 # MyISAM Key_buffer_read_hits (1 - Key_reads/Key_read_requests) * 100 82 key_buffer_read_hits=`compute "(1-$Key_reads/$Key_read_requests)*100"`% 83 84 # MyISAM Key_buffer_write_hits (1 - Key_writes/Key_write_requests) * 100 85 key_buffer_write_hits=`compute "(1-$Key_writes/$Key_write_requests)*100"`% 86 87 # Query_cache_hits (Qcache_hits / (Qcache_hits + Qcache_inserts)) * 100% 88 query_cache_hits=`compute "$Qcache_hits/($Qcache_hits+$Qcache_inserts)*100"`% 89 90 # Innodb_buffer_read_hits (1 - Innodb_buffer_pool_reads/Innodb_buffer_pool_read_requests) * 100 91 innodb_buffer_read_hits=`compute "(1-$Innodb_buffer_pool_reads/$Innodb_buffer_pool_read_requests)*100"`% 92 93 # Thread_cache_hits (1 - Threads_created / Connections) * 100% 94 thread_cache_hits=`compute "(1-$Threads_created/$Connections)*100"`% 95 96 # Slow_queries_per_second Slow_queries / Uptime * 60 97 slow_queries_per_second=`compute "$Slow_queries/$Uptime"` 98 99 # Select_full_join_per_second Select_full_join / Uptime * 60 100 select_full_join_per_second=`compute "$Select_full_join/$Uptime*60"` 101 102 # select_full_join_in_all_select (Select_full_join / Com_select) * 100 103 select_full_join_in_all_select=`compute "($Select_full_join/$Com_select)*100"`% 104 105 # MyISAM Lock Contention (Table_locks_waited / Table_locks_immediate) * 100 106 myisam_lock_contention=`compute "($Table_locks_waited/$Table_locks_immediate)*100"`% 107 108 # Temp_tables_to_disk (Created_tmp_disk_tables / Created_tmp_tables) * 100 109 temp_tables_to_disk_ratio=`compute "($Created_tmp_disk_tables/$Created_tmp_tables)*100"`% 110 111 # print formated MySQL status report 112 title="******************** MySQL--${HOST}--${PORT} ***********************" 113 width=$((`echo "$title"|wc -c`-1)) 114 115 echo "$title" 116 117 export IFS=':' 118 while read name value ;do 119 printf "%36s :/t%10s/n" $name $value 120 done 99%):$key_buffer_read_hits 130 MyISAM Key buffer write hits:$key_buffer_write_hits 131 Query cache hits:$query_cache_hits 132 InnoDB buffer read hits(>95%):$innodb_buffer_read_hits 133 Thread cache hits(>90%):$thread_cache_hits 134 Slow queries per second:$slow_queries_per_second 135 Select full join per second:$select_full_join_per_second 136 Select full join in all select:$select_full_join_in_all_select 137 MyiSAM lock contention( #Python版<img class="code_img_closed lazy" src="/static/imghwm/default1.png" data-src="http://img.bitscn.com/upimg/allimg/c140719/1405L9330U940-33564.jpg" id="code_img_closed_547cb232-79f2-4f40-9763-d38b744e9424" alt=""><img class="code_img_opened lazy" src="/static/imghwm/default1.png" data-src="http://img.bitscn.com/upimg/allimg/c140719/1405L9331093P-423U.jpg" onclick="cnblogs_code_hide('547cb232-79f2-4f40-9763-d38b744e9424',event)" id="code_img_opened_547cb232-79f2-4f40-9763-d38b744e9424" style="max-width:90%" alt="">View Code <pre class="brush:php;toolbar:false"> 1 #!/usr/bin/env python 2 3 #-*- coding: utf-8 -*- 4 5 # Script Name: mysql_status_check.py 6 7 # Description: check mysql servers status 8 9 # Author: Bruce.Zuo 10 11 # Create Date: 2012/06/05 12 13 import os,sys 14 15 import MySQLdb 16 17 import getpass 18 19 20 21 host=raw_input("host:") 22 23 user=raw_input("user:") 24 25 password=getpass.getpass() 26 27 28 29 try: 30 31 conn = MySQLdb.connect(host = host, user=user ,passwd = password, db = 'test') 32 33 except MySQLdb.ERROR,e: 34 35 print "Error %d:%s"%(e.args[0],e.args[1]) 36 37 exit(1) 38 39 cursor=conn.cursor() 40 41 42 43 cursor.execute('show global status;') 44 45 result_set=cursor.fetchall() 46 47 cursor.close() 48 49 conn.close() 50 51 52 53 def get_value(key_name): 54 55 for rows in result_set: 56 57 if rows[0]==key_name: 58 59 return float(rows[1]) 60 61 62 63 print ('MySQL-'+host+'-3306').center(60,'*') 64 65 print 'Uptime:'.rjust(40),get_value('Uptime') 66 67 print 'Threads_connected:'.rjust(40),get_value('Threads_connected') 68 69 print 'QPS:'.rjust(40),round(get_value('Questions') / get_value('Uptime'),2) 70 71 print 'TPS:'.rjust(40),round(get_value('Com_commit')+get_value('Com_rollback') / get_value('Uptime'),2) 72 73 reads=get_value('Com_select')+ get_value('Qcache_hits') 74 75 writes=get_value('Com_insert')+get_value('Com_update')+get_value('Com_delete')+get_value('Com_replace') 76 77 print 'Reads:'.rjust(40),get_value('Com_select')+ get_value('Qcache_hits') 78 79 print 'Writes:'.rjust(40),get_value('Com_insert')+get_value('Com_update')+get_value('Com_delete')+get_value('Com_replace') 80 81 print 'Read/Writes Ratio:'.rjust(40),round(reads / writes,2),'%' 82 83 print 'MyISAM Key buffer read hits(>99%):'.rjust(40),round(1-get_value('Key_reads') / (get_value('Key_read_requests')*100),2),'%' 84 85 print 'MyISAM Key buffer write hits:'.rjust(40),round(1-get_value('Key_writes') / (get_value('Key_write_requests')*100),2),'%' 86 87 print 'Query cache hits:'.rjust(40),round(get_value('Qcache_hits') / (get_value('Qcache_hits')+get_value('Qcache_inserts'))*100,2),'%' 88 89 print 'InnoDB buffer read hits(>95%):'.rjust(40),round(1-get_value('Innodb_buffer_pool_reads') / (get_value('Innodb_buffer_pool_read_requests')*100),2),'%' 90 91 print 'Thread cache hits(>90%):'.rjust(40),round(1-get_value('Threads_created') / (get_value('Connections')*100),2),'%' 92 93 print 'Slow queries per second:'.rjust(40),round(get_value('Slow_queries') / get_value('Uptime'),2) 94 95 print 'Select full join per second:'.rjust(40),round(get_value('Select_full_join') / get_value('Uptime'),2) 96 97 print 'Select full join in all select:'.rjust(40),round(get_value('Select_full_join') / (get_value('Com_select')*100),2),'%' 98 99 print 'MyiSAM lock contention( <p>#根据这个方法,可以添加更多的状态项。</p> <p>#效果图</p> <p><img src="/static/imghwm/default1.png" data-src="http://img.bitscn.com/upimg/allimg/c140719/1405L933135940-593L.jpg" class="lazy" alt=""></p> bitsCN.com

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于索引优化器工作原理的相关内容,其中包括了MySQL Server的组成,MySQL优化器选择索引额原理以及SQL成本分析,最后通过 select 查询总结整个查询过程,下面一起来看一下,希望对大家有帮助。

sybase是基于客户/服务器体系结构的数据库,是一个开放的、高性能的、可编程的数据库,可使用事件驱动的触发器、多线索化等来提高性能。

visual foxpro数据库文件是管理数据库对象的系统文件。在VFP中,用户数据是存放在“.DBF”表文件中;VFP的数据库文件(“.DBC”)中不存放用户数据,它只起将属于某一数据库的 数据库表与视图、连接、存储过程等关联起来的作用。

数据库系统由4个部分构成:1、数据库,是指长期存储在计算机内的,有组织,可共享的数据的集合;2、硬件,是指构成计算机系统的各种物理设备,包括存储所需的外部设备;3、软件,包括操作系统、数据库管理系统及应用程序;4、人员,包括系统分析员和数据库设计人员、应用程序员(负责编写使用数据库的应用程序)、最终用户(利用接口或查询语言访问数据库)、数据库管理员(负责数据库的总体信息控制)。

microsoft sql server是Microsoft公司推出的关系型数据库管理系统,是一个全面的数据库平台,使用集成的商业智能(BI)工具提供了企业级的数据管理,具有使用方便可伸缩性好与相关软件集成程度高等优点。SQL Server数据库引擎为关系型数据和结构化数据提供了更安全可靠的存储功能,使用户可以构建和管理用于业务的高可用和高性能的数据应用程序。

结构层次是“数据库→数据表→记录→字段”;字段构成记录,记录构成数据表,数据表构成了数据库。数据库是一个完整的数据的记录的整体,一个数据库包含0到N个表,一个表包含0到N个字段,记录是表中的行。

go语言可以写数据库。Go语言和其他语言不同的地方是,Go官方没有提供数据库驱动,而是编写了开发数据库驱动的标准接口,开发者可以根据定义的接口来开发相应的数据库驱动;这样做的好处在于,只要是按照标准接口开发的代码,以后迁移数据库时,不需要做任何修改,极大方便了后期的架构调整。

mysql查询为什么会慢,关于这个问题,在实际开发经常会遇到,而面试中,也是个高频题。遇到这种问题,我们一般也会想到是因为索引。那除开索引之外,还有哪些因素会导致数据库查询变慢呢?


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

禅工作室 13.0.1
功能强大的PHP集成开发环境

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具