我为提高mysql性能做出调整的配置项(一)

2015-01-23 22:03:57 · 作者: · 浏览: 17
skip-external-locking:跳过外部锁定。要明白这个参数,必须先了解external-locking(外部锁定,作用是为MYISAM数据表在多进程【多个服务公用同一个 数据库目录】访问下锁定),大多数情况下,我们的 mysql服务都是单进程服务的,从mysql官网上看,skip-external-locking参数默认情况下是ON的,
mysql> show variables like '%skip%';  
+------------------------+-------+  
| Variable_name          | Value |  
+------------------------+-------+  
| skip_external_locking  | ON    |  

?

?
在配置文件[mysqld]下开启这个参数OK。
?
key_buffer_size = 256M:为MYISAM数据表开启供线程共享的索引缓存。我们的项目中数据表基本上用的是INNODB引擎,所以这个参数暂时不进行调整
?
max_allowed_packet = 16M:服务端最大允许接收的数据包大小。在没有调整该配置项的时候,服务端默认是4M。当然这个参数和mysql(默认16M)和mysqldump(默认为24M,我已经调整为16M)中的数据包大小有关系,一般情况下1M就可以,官方建议如果使用了blog或者更大的字符串时进行该参数的调整,一般情况下,数据库会被初始化为net_buffer_length(最小1024byte,最大是1M,默认是16KB)的大小。
?
table_open_cache = 512:所有线程打开表的数目(默认设置大小为1000)。如果opened_tables很大并且不经常使用flush tables,官方建议我们增加该参数的大小。这个值并不是越大越好,需要根据实际情况下open_tables和opened_tables的综合进行调整
?
sort_buffer_size = 512K:需要排序会话的缓存大小,是针对每一个connection的,这个值也不会越大越好,默认大小是256kb,过大的配置会消耗更多的内存。我个人还没有测试
?
read_buffer_size = 512K:为需要全表扫描的MYISAM数据表线程指定缓存,也是针对每个connection的,这个参数暂时我也不需要太关注。
Each thread that does a sequential scan for a MyISAM table allocates a buffer of this size (in bytes)  
for each table it scans. If you do many sequential scans, you might want to increase this value, which  
defaults to 131072. The value of this variable should be a multiple of 4KB. If it is set to a value that is not  
a multiple of 4KB, its value will be rounded down to the nearest multiple of 4KB.  
This option is also used in the following context for all search engines:  
? For caching the indexes in a temporary file (not a temporary table), when sorting rows for ORDER BY.  
? For bulk insert into partitions.  
? For caching results of nested queries.  
and in one other storage engine-specific way: to determine the memory block size for MEMORY tables.  
The maximum permissible setting for read_buffer_size is 2GB.  
For more information about memory use during different operations, see Section 8.11.4.1, “How MySQL  
Uses Memory”.  

?

?
read_rnd_buffer_size = 1M:首先,该变量可以被任何存储引擎使用,当从一个已经排序的键值表中读取行时,会先从该缓冲区中获取而不再从磁盘上获取。默认为256K。
This variable is used for reads from MyISAM tables, and, for any storage engine, for Multi-Range Read  
optimization.  
When reading rows from a MyISAM table in sorted order following a key-sorting operation, the rows are  
read through this buffer to avoid disk seeks. See Section 8.2.1.15, “ORDER BY Optimization”. Setting  
the variable to a large value can improve ORDER BY performance by a lot. However, this is a buffer  
Server System Variables  
627  
allocated for each client, so you should not set the global variable to a large value. Instead, change the  
session variable only from within those clients that need to run large queries.  
The maximum permissible setting for read_rnd_buffer_size is 2GB.  

?

thread_cache_size = 18:有多少线程供服务缓存使用。
?
How many threads the server should cache for reuse. When a client disconnects, the client's threads  
are put in the cache if there are fewer than thread_cache_size threads there. Requests for threads  
are satisfied by reusing threads taken from the cache if possible, and only when the cache is empty is  
a new thread created. This variable can be increased to improve performance if you have a lot of new  
connections. Normally, this does not provide a notable performance improvement if you have a good