mysiam表参数详解

http://imysql.cn/2008_09_27_deep_into_mysql_sort_buffer

http://my.oschina.net/realfighter/blog/364420

要想提高MySQL的性能,首先就是必须对mysql的配置参数进行了解,在了解了mysql的配置参数后,根据自己的项目需要以及运行环境,再做出相应的调整,那么以下这些参数是经过对mysql的官方配置参数说明、网上资料查询,以及自己的各种实验得出的个人结论。

  1. 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。

  2. key_buffer_size = 256M:为MYISAM数据表开启供线程共享的索引缓存。我们的项目中数据表基本上用的是INNODB引擎,所以这个参数暂时不进行调整,有需要的可以参考http://database.51cto.com/art/201010/229939.htm
  3. max_allowed_packet = 16M:服务端最大允许接收的数据包大小。在没有调整该配置项的时候,服务端默认是4M。当然这个参数和mysql(默认16M)和mysqldump(默认为24M,我已经调整为16M)中的数据包大小有关系,一般情况下1M就可以,官方建议如果使用了blog或者更大的字符串时进行该参数的调整,一般情况下,数据库会被初始化为net_buffer_length(最小1024byte,最大是1M,默认是16KB)的大小。
  4. table_open_cache = 512:所有线程打开表的数目(默认设置大小为1000)。如果opened_tables很大并且不经常使用flush tables,官方建议我们增加该参数的大小。这个值并不是越大越好,需要根据实际情况下open_tables和opened_tables的综合进行调整,详细可见http://www.cnblogs.com/suredandan/p/4010931.html
  5. sort_buffer_size = 512K:需要排序 会话 的缓存大小,是针对每一个connection的,这个值也不会越大越好,默认大小是256kb,过大的配置会消耗更多的内存。我个人还没有测试,可以查看http://bbs.chinaunix.net/thread-1805254-1-1.html
  6. 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”.
  7. 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.

    另外可参见http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=3642777&highlight=

  8. 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
    thread implementation. However, if your server sees hundreds of connections per second you should
    normally set thread_cache_size high enough so that most new connections use cached threads. By
    examining the difference between the Connections and Threads_created status variables, you can
    see how efficient the thread cache is. For details, see Section 5.1.6, “Server Status Variables”.
    The default value is based on the following formula, capped to a limit of 100:
    8 + (max_connections / 100)
    This variable has no effect for the embedded server (libmysqld) and as of MySQL 5.7.2 is no longer
    visible within the embedded server.
  9. query_cache_size= 8M:分配给查询缓存的内存大小。要配合query_cache_type使用,默认是不开启的。只从该参数的表面介绍来看,似乎值设置的越大,带来的效果会更好,但是请注意,查询缓存的工作原理,一个select语句过来后,数据库将查询结果缓存到cache中,等同样的select查询过来后,如果这段时间内该查询结果没有发生变化时,数据库将cache中将缓存结果返回,那么假如查询的相关数据表增删改特别多的话,数据表变更的这段时间内,要将cache失效,然后再更新数据,对于增删改来说,花费的时间就很多了,所以要有所权衡,这个参数我会在将来进行相关测试数据整理。
    By default, the query cache is
    disabled. This is achieved using a default value of 1M, with a default for query_cache_type of
    0. (To reduce overhead significantly if you set the size to 0, you should also start the server with
    query_cache_type=0.
    The permissible values are multiples of 1024; other values are rounded down to the nearest multiple.
    Note that query_cache_size bytes of memory are allocated even if query_cache_type is set to 0.
    See Section 8.9.3.3, “Query Cache Configuration”, for more information.
    The query cache needs a minimum size of about 40KB to allocate its structures. (The exact size
    depends on system architecture.) If you set the value of query_cache_size too small, a warning will
    occur, as described in Section 8.9.3.3, “Query Cache Configuration”.
  10. query_cache_type = 1:1表示缓存所有查询,2表示缓存select sql_cache的查询,看如下内容
    0 or OFF Do not cache results in or retrieve results from the query cache. Note that
    this does not deallocate the query cache buffer. To do that, you should set
    query_cache_size to 0.
    1 or ON Cache all cacheable query results except for those that begin with SELECT
    SQL_NO_CACHE.
    2 or DEMAND Cache results only for cacheable queries that begin with SELECT SQL_CACHE.
  11. set global max_connections = 500:注意这个是通过命令行设置最大连接数,不是配置在配置文件的,因为我在配置文件里面尝试修改,重启mysql服务后并没有起效,通过该参数设置以后,重启服务后,依然没有起效,如果有朋友知道这个原因的话,请告知。如果说你的项目使用的是spring的连接池的时候,我认为spring个connection就对应的这个连接。根据你项目的需求而定。

key_buffer_size

Index blocks for MyISAM tables are buffered and are shared by all threads. key_buffer_size is the size of the buffer used for index blocks. The key buffer is also known as the key cache.

时间: 2024-11-08 23:14:43

mysiam表参数详解的相关文章

MySQL配置文件mysql.ini参数详解、MySQL性能优化

MySQL配置文件mysql.ini参数详解.MySQL性能优化 my.ini(Linux系统下是my.cnf),当mysql服务器启动时它会读取这个文件,设置相关的运行环境参数. my.ini分为两块:Client Section和Server Section.   Client Section用来配置MySQL客户端参数.   要查看配置参数可以用下面的命令: show variables like '%innodb%'; # 查看innodb相关配置参数 show status like

PHP CURL参数详解

PHP CURL参数详解 curl用法:cookie及post一.cookie用法 <?php $cookie_jar = tempnam('./tmp','cookie'); // login $c=curl_init('http://login_url?username=... curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar); curl_exec($c); 

ASP.NET性能监视参数详解

性能监视器- Performance Monitor 性能监视器是Windows自带的系统资源和性能监视工具. 性能监视器能够量化地提供CPU使用率, 内存分配状况, 异常派发情况, 线程调度频率等信息. ASP.NET能够提供每秒钟的请求数目, 请求响应时间等等. 性能监视器能够监视一段时间内上述资源的利用情况, 提供平均值和峰值. 性能监视器有助于获取关于性能的具体指标, 监视问题出现时系统资源的变化情况. 通过检查性能监视器中一些重要计数器的变化情况, 往往能够找到一些比较有用的线索. 比

LINUX下ORACLE相关的内核参数详解

ORACLE相关的内核参数详解 1.kernel.sem [[email protected] ~]# cat /proc/sys/kernel/sem 250         32000    100         142 [[email protected] ~]#  ipcs -sl ------ Semaphore Limits -------- max number of arrays = 142 max semaphores per array = 250 max semaphor

Redis配置文件redis.conf参数详解

redis.conf配置文件参数详解 # Redis configuration file example. ########################################## GENERAL ######################################## daemonize yes    #是否开启在后台运行redis,默认为no,不开启 pidfile /var/run/redis/redis.pid    #redis在后台运行时,默认pid文件的存放路

mysql5.6主从参数详解

mysql5.6的主从相当的不错,增加了不少参数,提升了主从同步的安全和效率,以下是mysql5.6主从参数详解. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ######################################### server_id = 2 #binlog log-bin = /data1/mysql/binlog/binlog binlog_format

谷歌搜索参数url参数详解

谷歌搜索表单参数url参数详解 q(Query):查询的关键词,搜索查询q是必需的URL参数之一,其他都是可选的. 当q的值包含多个单词时,用加号分隔每个单词.(text) hl(Interface Language):Google搜索的界面语言hl=zh-CN简体中文语言界面,我们用的Google中文就是这个参数.hl=zh-TW繁体中文语言界面,港台地区常使用hl=en-英文语言界面 lr(Language Restrict):搜索内容的语言限定限定只搜索某种语言的网页.如果lr参数为空,则

mysql简单的单表查询详解

mysql简单的单表查询详解 MySQL的查询操作: 单表查询:简单查询 多表查询:连续查询 联合查询: 选择和投影: 投影:挑选要显示的字段 选择:挑选符合条件的行 投影:SELECT 字段1, 字段2, ... FROM tb_name;  SELECT * FROM tb_name; 选择:SELECT 字段1, ... FROM tb_name WHERE 子句; 布尔条件表达式 mysql> CREATE TABLE students (SID INT UNSIGNED AUTO_IN

Linux字符集和系统语言设置-LANG,locale,LC_ALL,POSIX等命令及参数详解

博文说明[前言]: 本文将通过个人口吻介绍Linux字符集和系统语言设置,包括LANG,locale,LC_ALL,POSIX等命令及参数详解的相关知识,在目前时间点[2017年6月21号]下,所掌握的技术水平有限,可能会存在不少知识理解不够深入或全面,望大家指出问题共同交流,在后续工作及学习中如发现本文内容与实际情况有所偏差,将会完善该博文内容. 本文参考文献引用链接: 1.http://blog.csdn.net/z4213489/article/details/7937894[好文,必看]