各位用户为了找寻关于mysql优化之query_cache_limit参数说明的资料费劲了很多周折。这里教程网为您整理了关于mysql优化之query_cache_limit参数说明的相关资料,仅供查阅,以下为您介绍关于mysql优化之query_cache_limit参数说明的详细内容

query_cache_limit

query_cache_limit指定单个查询能够使用的缓冲区大小,缺省为1M。

优化query_cache_size

  从4.0.1开始,MySQL提供了查询缓冲机制。使用查询缓冲,MySQL将SELECT语句和查询结果存放在缓冲区中,今后对于同样的 SELECT语句(区分大小写),将直接从缓冲区中读取结果。根据MySQL用户手册,使用查询缓冲最多可以达到238%的效率。

  通过检查状态值Qcache_*,可以知道query_cache_size设置是否合理(上述状态值可以使用SHOW STATUS LIKE ‘Qcache%'获得)。如果Qcache_lowmem_prunes的值非常大,则表明经常出现缓冲不够的情况,如果Qcache_hits的值也非常大,则表明查询缓冲使用非常频繁,此时需要增加缓冲大小;如果Qcache_hits的值不大,则表明你的查询重复率很低,这种情况下使用查询缓冲反而会影响效率,那么可以考虑不用查询缓冲。此外,在SELECT语句中加入SQL_NO_CACHE可以明确表示不使用查询缓冲。

  与查询缓冲有关的参数还有query_cache_type、query_cache_limit、query_cache_min_res_unit。query_cache_type指定是否使用查询缓冲,可以设置为0、1、2,该变量是SESSION级的变量。query_cache_limit指定单个查询能够使用的缓冲区大小,缺省为1M。query_cache_min_res_unit是在4.1版本以后引入的,它指定分配缓冲区空间的最小单位,缺省为4K。检查状态值Qcache_free_blocks,如果该值非常大,则表明缓冲区中碎片很多,这就表明查询结果都比较小,此时需要减小 query_cache_min_res_unit。

因为我们的服务器内容96G所以如下设置

query_cache_size = 128M query_cache_limit = 8M

比较完整的my.ini文件,大家可以根据自己的服务器适当调整,以防止mysql无法运行,这个是针对mysql5.6版本的。

[client] port = 3306 socket = /tmp/mysql.sock default-character-set = utf8 #设置客户端的字符编码 [mysqld] # generic configuration options port = 3306 socket = /tmp/mysql.sock basedir="E:/database/mysql/" datadir="E:/database/mysql/data/" tmpdir = "E:/database/mysql/tmp/" #*** char set *** character-set-server = utf8 #设置服务器端的字符编码

#下面三个参数默认12500,1400,2000 performance_schema_max_table_instances = 20000 table_definition_cache = 2000 table_open_cache = 4096 #*** network *** back_log = 1024 #skip-networking #默认没有开启 max_connections = 10000 #max_connect_errors = 3000 table_open_cache = 4096 #external-locking #默认没有开启 max_allowed_packet = 256M max_heap_table_size = 128M secure_file_priv='' explicit_defaults_for_timestamp=true concurrent_insert=2 #*** timeout *** interactive_timeout=1000 wait_timeout=1000

# *** global cache *** read_buffer_size = 64M read_rnd_buffer_size = 64M sort_buffer_size = 64M join_buffer_size = 1024M # *** thread *** thread_cache_size = 64 # thread_concurrency = 8 thread_stack = 512K # *** query cache *** query_cache_size = 128M query_cache_limit = 8M # *** index *** ft_min_word_len = 8 #memlock #默认没有开启 default-storage-engine=MYISAM innodb=OFF default-tmp-storage-engine=MYISAM transaction_isolation = REPEATABLE-READ # *** tmp table *** tmp_table_size = 1024M # *** bin log *** #log-bin=mysql-bin binlog_cache_size = 4M binlog_format=mixed #log_slave_updates #默认没有开启 #log #默认没有开启,此处是查询日志,开启会影响服务器性能 log_warnings #开启警告日志 # *** slow query log *** slow_query_log long_query_time = 10 # *** Replication related settings #server-id = 1 #server-id = 2 #master-host = <hostname> #master-user = <username> #master-password = <password> #master-port = <port> #read_only #*** MyISAM Specific options #myisam_recover key_buffer_size = 2048M bulk_insert_buffer_size = 128M myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 myisam_recover_options=force,backup # *** INNODB Specific options *** #skip-innodb #默认没有开启 loose-innodb-trx=0 loose-innodb-locks=0 loose-innodb-lock-waits=0 loose-innodb-cmp=0 loose-innodb-cmp-per-index=0 loose-innodb-cmp-per-index-reset=0 loose-innodb-cmp-reset=0 loose-innodb-cmpmem=0 loose-innodb-cmpmem-reset=0 loose-innodb-buffer-page=0 loose-innodb-buffer-page-lru=0 loose-innodb-buffer-pool-stats=0 loose-innodb-metrics=0 loose-innodb-ft-default-stopword=0 #loose-innodb-ft-inserted=0 loose-innodb-ft-deleted=0 loose-innodb-ft-being-deleted=0 loose-innodb-ft-config=0 loose-innodb-ft-index-cache=0 loose-innodb-ft-index-table=0 loose-innodb-sys-tables=0 loose-innodb-sys-tablestats=0 loose-innodb-sys-indexes=0 loose-innodb-sys-columns=0 loose-innodb-sys-fields=0 loose-innodb-sys-foreign=0 loose-innodb-sys-foreign-cols=0

[mysqldump] quick max_allowed_packet = 256M

[mysql] no-auto-rehash

[myisamchk] key_buffer_size = 2048M sort_buffer_size = 2048M read_buffer = 32M write_buffer = 32M

[mysqlhotcopy] interactive-timeout

[mysqld_safe] open-files-limit = 10240 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

如果想优化mysql可以结合MySQL的Query Cache详解的文章。