optimzingmysql酷讯网.ppt
《optimzingmysql酷讯网.ppt》由会员分享,可在线阅读,更多相关《optimzingmysql酷讯网.ppt(47页珍藏版)》请在三一办公上搜索。
1、,Optimzing mysql,I feel the need.the need for speed.,壮志凌云(top gun),性能监控 10分性能优化 20分常见的架构 10分Tools and tips 10分,性能监控,操作系统级别的Mysql级别,操作系统,vmstat iostatfreetopsarmpstatuptime,netstatstrace,mysql,Show processlist Mysqlreport http:/-uxxx p-i 1-r extendedstatus|grep-v“|0”Innotop Show global status,show in
2、ondb status show session status;Mytop ExplainProfilingMysqldumpslow mysqlslasysbench,vmstat,基本的物理和虚拟内存的使用和一些基本的系统统计信息Vmstat S M Vmstat 5 5Swap颠簸现象Top ps axl,iostat,度量磁盘i/o,cpu和设备io使用Iostat-c iostat dx 5%iowait并发请求的数量 并发=(r/s+w/s)*(svctm/1000)(从头到尾服务请求时间),Cpu密集型机器,Io密集型,Swap idle,谁可能导致高的cpu usagequer
3、y,joins,every进程切换,锁表内存排序临时表加密算法谁可能导致高的disk usage临时表硬盘上排序 start with an idea,then look for infromation support it,netstat,服务链接状态 netstat-nat|awk print$6|sort|uniq-c|sort-n 是否被dos:netstat-atun|awk print$5|cut-d:-f1|sed-e/$/d|sort|uniq-c|sort-n/bin/netstat-na|grep ESTABLISHED|awk print$5|awk-F:print$1|
4、sort|uniq-c|sort-rn|grep-v-E 172.16|127.0|awk if($2!=null&$110)print$1,$2,其它,Top:Ps:ps aux|awk if($6(1024*15)print$2|grep-v PID,分析服务器,MysqlreportMysqladmin mysqladmin extended-r-i 10|grep v“|0”-uroot pInnotop.Show global statusShow innodb status,分析查询,Show processlistFlush statusShow session status l
5、ike Select%Show session status like Handler%Show session status like Sort%Show session status like Create%Set profiling,分析mysql连接,netstat-ntp|grep:40327 netstat-ntp|grep 10940/mysqldgrep 3306/etc/servicesps-eaf|grep UID|10940lsof-i-P|grep 10942,性能优化,操作系统 mysql应用程序,操作系统,不要交换区。如果内存不足,增加更多的内存或配置你的系统使用较
6、少内存。flick:echo 0/proc/sys/vm/swappiness innodb_flush_method=O_DIRECT不要使用NFS磁盘(会有NFS锁定的问题)。增加系统和MySQL服务器的打开文件数量。(在safe_mysqld脚本中加入ulimit-n#)。增加系统的进程和线程数量。选择使用哪种文件系统。在Linux上的Reiserfs对于打开、读写都非常快。文件检查只需几秒种。,Mysql配置,Mysiam 缓存key_buffer_size key_buffer_1.key_buffer_size=1G show variables like key_buffer_s
7、ize;show global status like key_read%;key_cache_miss_rate Key_reads/Key_read_requests*100%du sch find/mysqldatapath/-name“*.MYI”Innodb 缓冲池innodb_bufer_pool_size 80%show status like Innodb_buffer_pool_read%Innodb_buffer_pool_read_requests/Innodb_buffer_pool_readsshow innodb statusG BUFFER POOL AND ME
8、MORY Total memory allocated 4668764894;,查询缓存,show global status like Qcache%;show variables like query_cache%;查询缓存利用率=(query_cache_size Qcache_free_memory)/query_cache_size*100%查询缓存命中率=(Qcache_hits Qcache_inserts)/Qcache_hits*100%,innodb,刷写日志缓冲 Innodb_flush_log_at_trx_commit 0 1 2 打开并清写日志和文件 innodb_
9、flush_method,myisam,初始化:initial=key_buffer_size+query_cache_size连接 per_connection=(sort_buffer_size+read_rnd_buffer_size+join_buffer_size+read_buffer_size+thead_stack)总和:initial+max_connections*per_connection initial+(max_connections*per_connection)/3),innodb,初始化:initial=innodb_buffer_pool_size+quer
10、y_cache_size连接per_connection=(sort_buffer_size+join_buffer_size+thead_stack+binlog_cache_size+read_buffer_size+read_rnd_buffer_size)总和:initial+max_connections*per_connection initial+(max_connections*per_connection)/3),数据类型选择,更小通常更好,慷慨并不明智简单就好 使用mysql内建的类型保存日期和时间,使用timestamp 保存,空间是datetime一半 使用整数保存ip
11、15 bytes for char(15)vs.4 bytes for the integer ip2long()和 long2ip()inet_aton3 尽量避免null4 Char/varcha的选择 对于MyISAM而言,如果没有VARCHAR,TEXT等变长类型,那么每行数据所占用的空间都是定长的(Fixed),俗称静态表,相对应的就是动态表。当执行一次查询时,MySQL可以通过索引文件找到所需内容的实际行号,此时,由于每行数据所占用的空间都是定长的(Fixed),所以可以通过查询到的实际行号直接定位到数据文件的具体位置,对于InnoDB而言,数据行是没有所谓定长与否的概念的,这是由
12、其结构所决定的:在InnoDB中,数据就位于Primary Key的B-Tree叶节点之上而除Primary Key之外的索引被称为Secondary Index,它们直接指向Primary Key。用char来代替varchar,MyISAM是这样,InnoDB则相反5 使用enum 代替字符串类型 select internet+0 from hotel_info group by internet;,索引,隔离列select*from tablename where id+1=5Select*where TO_DAYS(CURRENT_DATE)TO_DAYS(data_col)=dat
13、e_sub(current_date,interval 10 day)Select*where data_col=date_sum(2010-04-12,interval 10 day)EXPLAIN SELECT*FROM film WHERE title LIKE Tr%GEXPLAIN SELECT*FROM film WHERE LEFT(title,2)=Tr G组合索引 前缀索引覆盖索引合并索引去除多余索引和重复索引 create table test(id int not null primary key,unique(id),index(id),合并索引,索引合并方法用于通过r
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- optimzingmysql 酷讯网

链接地址:https://www.31ppt.com/p-5441952.html