MySQl调优十参数-整理.docx_第1页
MySQl调优十参数-整理.docx_第2页
MySQl调优十参数-整理.docx_第3页
MySQl调优十参数-整理.docx_第4页
MySQl调优十参数-整理.docx_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

比如系统信息为:Linux localhost.localdomain 2.6.18-238.el5 #1 SMP Thu Jan 13 15:51:15 EST 2011 x86_64 x86_64 x86_64 GNU/Linux1 Key buffershow variables like %key_buffer_size%16M 太小,修改为32MA、 参数key_buffer_size只对myisam引擎的表起作用;B、 它决定索引处理的速度,尤其是索引读的速度;C、 评估 这个参数是否设置合理 可以检查两个状态值 show status like %key_read%;D、 Key_read_requests代表 总的请求数,key_reads代表读取磁盘数;E、 key_reads / key_read_requests应该尽可能的低,至少是1:100,1:1000更好;F、 另外一个估计key_buffer_size的办法把你数据库的每个表的索引所占空间大小加起来看看。G、 该参数值设置的过大反而会是服务器整体效率降低!H、 对于内存在4GB左右的服务器该参数可设置为384M或512M。2 Query cacheA、 query cache主要是将SELECT语句和查询结果存放在该缓冲区;B、 参数query_cache_size 的设置合理性可以检查db的状态:show status like %qcache%C、 参数query_cache_type指定是否使用查询缓冲;D、设置参数: query_cache_size = 32M query_cache_type= 1set global query_cache_type=1设置报错ERROR 1227 (42000): Access denied; you need the SUPER privilege for this operation使用bcsr登录bcsr_db数据库,需要bcsr的权限足够高,如root 才能设置权限。E、一段时间后服务器状态值:Qcache queries in cache 12737 表明目前缓存的条数 Qcache inserts 20649006 Qcache hits 79060095 看来重复查询率还挺高的 Qcache lowmem PRunes 617913有这么多次出现缓存过低的情况 Qcache not cached 189896 Qcache free memory 18573912目前剩余缓存空间 Qcache free blocks 5328 这个数字似乎有点大碎片不少 Qcache total blocks 30953 F、 结果表明:query cache值需要设置的更大一些;G、 Qcache_free_blocks,如果该值非常大,则表明缓冲区中碎片很多H、 Qcache_lowmem_prunes的值非常大,则表明经常出现缓冲不够的情况,同时Qcache_hits的值非常大,则表明查询缓冲使用非常频繁,此时需要增加缓冲大小Qcache_hits的值不大,则表明你的查询重复率很低,这种情况下使用查询缓冲反而会影响效率,那么可以考虑不用查询缓冲。此外,在SELECT语句中加入SQL_NO_CACHE可以明确表示不使用查询缓冲。3 Table cacheA、 table_cache指定表高速缓存的大小;为所有线程打开表的数量。增加该值能增加mysql要求的文件描述符的数量。MySQL对每个唯一打开的表需要2个文件描述符。默认数值是64,我把它改为512。 B、 每当MySQL访问一个表时,如果在表缓冲区中还有空间,该表就被打开并放入其中,这样可以更快地访问表内容;C、 通过检查峰值时间的状态值Open_tables和Opened_tables,可以决定是否需要增加table_cache的值。如果你发现open_tables等于table_cache,并且opened_tables在不断增长,那么你就需要增加table_cache的值了;D、 注意,不能盲目地把table_cache设置成很大的值。如果设置得太高,可能会造成文件描述符不足,从而造成性能不稳定或者连接失败。此时1 修改sysctl.conf文件2设置如下变量为4096或8192 前提4G内存4 Innodb buffer如果没开启innodb就开启,路径如:/etc/f查看f 将#注释的innodb的所有项开启即可。# Example MySQL config file for medium systems.# This is for a system with little memory (32M - 64M) where MySQL plays# an important part, or systems up to 128M where MySQL is used together with# other programs (such as a web server)# MySQL programs look for option files in a set of# locations which depend on the deployment platform.# You can copy this option file to one of those# locations. For information about these locations, see:# /doc/mysql/en/option-files.html# In this file, you can use all long options that a program supports.# If you want to know which options a program supports, run the program# with the -help option.# The following options will be passed to all MySQL clientsclient#password = your_passwordport = 3306socket = /tmp/mysql.sock# Here follows entries for some specific programs# The MySQL servermysqldport = 3306socket = /tmp/mysql.sockskip-locking # 避免MySQL的外部锁定,减少出错几率增强稳定性key_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8M# Dont listen on a TCP/IP port at all. This can be a security enhancement,# if all processes that need to connect to mysqld run on the same host.# All interaction with mysqld must be made via Unix sockets or named pipes.# Note that using this option without enabling named pipes on Windows# (via the enable-named-pipe option) will render mysqld useless!#skip-networking# Replication Master Server (default)# binary logging is required for replicationlog-bin=mysql-bin# binary logging format - mixed recommendedbinlog_format=mixed# required unique id between 1 and 232 - 1# defaults to 1 if master-host is not set# but will not function as a master if omittedserver-id = 1# Replication Slave (comment out master section to use this)# To configure this host as a replication slave, you can choose between# two methods :# 1) Use the CHANGE MASTER TO command (fully described in our manual) -# the syntax is:# CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=,# MASTER_USER=, MASTER_PASSWORD= ;# where you replace , , by quoted strings and# by the masters port number (3306 by default).# Example:# CHANGE MASTER TO MASTER_HOST=125.564.12.1, MASTER_PORT=3306,# MASTER_USER=joe, MASTER_PASSWORD=secret;# OR# 2) Set the variables below. However, in case you choose this method, then# start replication for the first time (even unsuccessfully, for example# if you mistyped the password in master-password and the slave fails to# connect), the slave will create a file, and any later# change in this file to the variables values below will be ignored and# overridden by the content of the file, unless you shutdown# the slave server, delete and restart the slaver server.# For that reason, you may want to leave the lines below untouched# (commented) and instead use CHANGE MASTER TO (see above)# required unique id between 2 and 232 - 1# (and different from the master)# defaults to 2 if master-host is set# but will not function as a slave if omitted#server-id = 2# The replication master for this slave - required#master-host = # The username the slave will use for authentication when connecting# to the master - required#master-user = # The password the slave will authenticate with when connecting to# the master - required#master-password = # The port the master is listening on.# optional - defaults to 3306#master-port = # binary logging - not required for slaves, but recommended#log-bin=mysql-bin# Uncomment the following if you are using InnoDB tables#innodb_data_home_dir = /usr/local/mysql/var#innodb_data_file_path = ibdata1:10M:autoextend#innodb_log_group_home_dir = /usr/local/mysql/var# You can set ._buffer_pool_size up to 50 - 80 %# of RAM but beware of setting memory usage too high#innodb_buffer_pool_size = 16M#innodb_additional_mem_pool_size = 2M# Set ._log_file_size to 25 % of buffer pool size#innodb_log_file_size = 5M#innodb_log_buffer_size = 8M#innodb_flush_log_at_trx_commit = 1#innodb_lock_wait_timeout = 50mysqldumpquickmax_allowed_packet = 16Mmysqlno-auto-rehash# Remove the next comment character if you are not familiar with SQL#safe-updatesmyisamchkkey_buffer_size = 20Msort_buffer_size = 20Mread_buffer = 2Mwrite_buffer = 2Mmysqlhotcopyinteractive-timeoutA、 innodb_buffer_pool_size - 这对Innodb表来说非常重要。Innodb相比MyISAM表对缓冲更为敏感。MyISAM可以在默认的 key_buffer_size 设置下运行的可以,然而Innodb在默认的 innodb_buffer_pool_size 设置下却跟蜗牛似的。B、 由于Innodb把数据和索引都缓存起来,无需留给操作系统太多的MySQL数据库内存,因此如果只需要用Innodb的话则可以设置它高达 70-80% 的可用内存。C、 如果你的数据量不大,并且不会暴增,那么无需把 innodb_buffer_pool_size 设置的太大了。D、 innodb_log_file_size 在高写入负载尤其是大数据集的情况下很重要。这个值越大则性能相对越高,但是要注意到可能会增加恢复时间。我经常设置为 64-512MB,跟据服务器大小而异。innodb_log_buffer_size 默认的设置在中等强度写入负载以及较短事务的情况下,服务器性能还可以。E、 innodb_flush_logs_at_trx_commit 是否为Innodb比MyISAM慢1000倍而头大?看来也许你忘了修改这个参数了。默认值是 1,这意味着每次提交的更新事务(或者每个事务之外的语句)都会刷新到磁盘中,而这相当耗费资源,尤其是没有电池备用缓存时。很多应用程序,尤其是从 MyISAM转变过来的那些,把它的值设置为 2 就可以了,也就是不把日志刷新到磁盘上,而只刷新到操作系统的缓存上。日志仍然会每秒刷新到磁盘中去,因此通常不会丢失每秒1-2次更新的消耗。如果设置为 0 就快很多了,不过也相对不安全了。MySQL服务器崩溃时就会丢失一些事务。设置为 2 指挥丢失刷新到操作系统缓存的那部分事务。5 back_log要求 MySQL 能有的连接数量。当主要MySQL线程在一个很短时间内得到非常多的连接请求,这就起作用,然后主线程花些时间(尽管很短)检查连接并且启动一个新线程。 back_log值指出在MySQL暂时停止回答新请求之前的短时间内多少个请求可以被存在堆栈中。只有如果期望在一个短时间内有很多连接,你需要增加它,换句话说,这值对到来的TCP/IP连接的侦听队列的大小。你的操作系统在这个队列大小上有它自己的限制。 试图设定back_log高于你的操作系统的限制将是无效的。当你观察你的主机进程列表,发现大量 264084 | unauthenticated user | xxx.xxx.xxx.xxx | NULL | Connect | NULL | login | NULL 的待连接进程时,就要加大 back_log 的值了。默认数值是50,我把它改为500。6 interac

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论