MySQl调优十参数-整理

上传人:平*** 文档编号:13353127 上传时间:2017-10-23 格式:DOCX 页数:13 大小:135.26KB
返回 下载 相关 举报
MySQl调优十参数-整理_第1页
第1页 / 共13页
MySQl调优十参数-整理_第2页
第2页 / 共13页
MySQl调优十参数-整理_第3页
第3页 / 共13页
MySQl调优十参数-整理_第4页
第4页 / 共13页
MySQl调优十参数-整理_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《MySQl调优十参数-整理》由会员分享,可在线阅读,更多相关《MySQl调优十参数-整理(13页珍藏版)》请在金锄头文库上搜索。

1、比如系统信息为: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

2、、 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_s

3、ize 的设置合理性可以检查 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、

4、一段时间后服务器状态值: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 值需要

5、设置的更大一些;G、 Qcache_free_blocks,如果该值非常大,则表明缓冲区中碎片很多H、 Qcache_lowmem_prunes 的值非常大,则表明经常出现缓冲不够的情况,同时Qcache_hits 的值非常大,则表明查询缓冲使用非常频繁,此时需要增加缓冲大小Qcache_hits 的值不大,则表明你的查询重复率很低,这种情况下使用查询缓冲反而会影响效率,那么可以考虑不用查询缓冲。此外,在 SELECT 语句中加入 SQL_NO_CACHE 可以明确表示不使用查询缓冲。3 Table cacheA、 table_cache 指定表高速缓存的大小;为所有线程打开表的数量。增加该值

6、能增加 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

7、 设置成很大的值。如果设置得太高,可能会造成文件描述符不足,从而造成性能不稳定或者连接失败。此时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 p

8、art, 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,

9、see:# http:/ 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

10、# 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_si

11、ze = 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 enabl

12、ing 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

13、 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 d

14、escribed 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=j

15、oe, 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 master.info file, and any later# change in this file to the variables values below will be ignored and# overridden by the content of the master.info file, unless you shutdown# the slave server, delete master.info and restart the slaver server.# For that

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号