MySQL中部分系统变量介绍

对比了一下不同环境下两台MySQL服务器的运行参数配置,除了文件名、路径等内容的差异外,还存在其他一些不同。借此机会简单罗列其中一部分并加以说明 ~


have_symlink                             DISABLED                                   YES

用以支持在表定义中指定数据目录和索引目录(全局静态系统变量)

 

innodb_additional_mem_pool_size          268435456        (256M)                                  67108864        (64M)

Deprecated

5.6.3

Command-Line Format

--innodb_additional_mem_pool_size=#

System Variable

Name

innodb_additional_mem_pool_size

Variable Scope

Global

Dynamic Variable

No

Permitted Values

Type

integer

Default

8388608

Min Value

2097152

Max Value

4294967295

 

innodb_buffer_pool_size                  2147483648        (2G)                                 8053063680        (7.5G)

Command-Line Format

--innodb_buffer_pool_size=#

System Variable

Name

innodb_buffer_pool_size

Variable Scope

Global

Dynamic Variable

No

Permitted Values(32-bit platforms)

Type

integer

Default

134217728

Min Value

5242880

Max Value

2**32-1

Permitted Values(64-bit platforms)

Type

integer

Default

134217728

Min Value

5242880

Max Value

2**64-1

 

innodb_file_format                       Antelope                                   Barracuda

Command-Line Format

--innodb_file_format=#

System Variable

Name

innodb_file_format

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values

Type

string

Default

Antelope

Valid Values

Antelope

Barracuda

InnoDB表的文件格式,当且仅当innodb_file_per_table开启时有效。一些特殊的InnoDB特性如compression需要Barracuda文件格式。

 

innodb_file_format_max                   Antelope                                   Barracuda

Command-Line Format

--innodb_file_format_max=#

System Variable

Name

innodb_file_format_max

Variable Scope

Global

Dynamic Variable

Ye

Permitted Values

Type

string

Default

Antelope

Valid Values

Antelope

Barracuda

Server刚启动时该值被设置为系统表空间中的文件格式。若Server创建或者打开了一张拥有”更高级别”文件格式的表,则该值被置为此文件格式。

 

innodb_flush_log_at_trx_commit           1                                          2

Command-Line Format

--innodb_flush_log_at_trx_commit[=#]

System Variable

Name

innodb_flush_log_at_trx_commit

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values

Type

enumeration

Default

1

Valid Values

0

1

2

用于控制性能和数据一致性之间的平衡。1:每次事务提交都会将InnoDB log buffer写进log file并且把log file刷入磁盘,不会导致数据丢失;0:每秒而不是每次事务提交进行一次刷InnoDB log buffer且将log file刷入磁盘的动作(一秒内可能有多次或者没有事务提交,另外,这里说的每秒并不是真正精确的一秒中刷一次),因此可能会造成大约一秒中内的事务丢失;2InnoDB log buffer会在每个事务提交时刷新一次,而日志文件大约每秒钟(这里的每秒同上,不是精确的一秒一次)往磁盘刷一次 ,这样,若仅是mysqld崩溃则会丢失一个事务,若是操作系统崩溃或者是系统断电最多丢失一秒钟的事务。

 MySQL5.6.6后引入了另外一个参数 innodb_flush_log_at_timeout,用于设置 InnoDB log的刷新频率,可以设置为1秒到2700秒之间的任何数字,默认值为1。这个参数和innodb_flush_log_at_trx_commit共同影响InnoDB log刷新策略,比如innodb_flush_log_at_trx_commit设置为0innodb_flush_log_at_timeout设置为2,则每两秒进行一次刷log bufferlog file的刷新,若nnodb_flush_log_at_trx_commit设置为2innodb_flush_log_at_timeout设置为2,则log buffer在每个事务提交时刷新一次而日志文件大约每2秒刷新到磁盘一次。

需要注意的是DDL变化和其他内部InnoDB活动对InnoDB日志的刷新独立于 innodb_flush_log_at_trx_commit 配置;另外InnoDB的崩溃恢复也与innodb_flush_log_at_trx_commit配置无关,事务要么被完全应用要么被完全清除。

为了保证持久性和一致性复制环境推荐的配置为:sync_binlog=1, innodb_flush_log_at_trx_commit=1. 

 

innodb_flush_method                        NULL                                         O_DIRECT

Command-Line Format

--innodb_flush_method=name

System Variable

Name

innodb_flush_method

Variable Scope

Global

Dynamic Variable

No

Permitted Values(Unix, <= 5.6.6)

Type

string

Default

NULL

Valid Values

fsync

littlesync

nosync

O_DSYNC

O_DIRECT

Permitted Values(Unix, >= 5.6.7)

Type

string

Default

NULL

Valid Values

fsync

O_DSYNC

littlesync

nosync

O_DIRECT

O_DIRECT_NO_FSYNC

Permitted Values(Windows)

Type

string

Default

async_unbuffered

Valid Values

normal

unbuffered

定义InnoDB刷数据到InnoDB数据文件和日志文件的方法,这一设置将影响IO吞吐量。在Unix-like 的系统中,若innodb_flush_method=NULL会默认使用fsync Unix-like的系统中可配置的参数包括:

fsync:默认设置,此时InnoDB使用fsync()系统调用刷数据和日志文件

O_DSYNC:此时InnoDBO_SYNC打开和刷日志文件,用fsync()刷数据文件。(之所以使用O_SYNC而不用O_DSYNC是因为后者在某些Unix like的系统上存在问题)。

littlesyncnosync当前不支持,仅用于内部测试。

O_DIRECT:InnoDB使用O_DIRECT打开数据文件,用fsync刷数据和日志文件,该选项只在一些GNU/Linux 版本、 FreeBSDSolaris上可用。

O_DIRECT_NO_FSYNCInnoDBflushing I/O期间使用O_DIRECT但跳过后续的fsync()系统调用。该配置仅适用于某些类型的文件系统,如,不适用于XFS文件系统。不确定文件系统是否需要fsync()时请使用O_DIRECT

上述各个配置对性能的影响最终还取决于具体的硬件配置和工作负载。所以,最好是在实际情况下就具体的硬件配置对不同的刷新方法进行基准测试。比如,可以通过 Innodb_data_fsyncs状态变量看每种设置下fsync次数。读写负载比例也将影响到最终的配置。比如,在具备硬件RAID控制器和后备电池写缓存时O_DIRECT配置可避免InnoDB buffer poolOS文件系统cache之间的双缓冲;又如,若InnoDB 数据和日志文件位于SANO_DSYNC设置或许可加速读操作较多的负载。

 

innodb_io_capacity                       200                                        20000

Command-Line Format

--innodb_io_capacity=#

System Variable

Name

innodb_io_capacity

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values(32-bit platforms)

Type

integer

Default

200

Min Value

100

Max Value

2**32-1

Permitted Values(64-bit platforms)

Type

integer

Default

200

Min Value

100

Max Value

2**64-1

设置InnoDB后台任务,如,从buffer pool刷新pages或者从change buffermerge数据,的I/O操作上限。对于具有较高的IO性能(如多块磁盘或者SSD盘)且比较繁忙的系统可适当增加该参数的值。需要注意的是该值是个全局的值,也即,是所有buffer pool实例共同的总的上限,该上限被平均分到各个buffer pool实例。该值应当设置为接近系统每秒允许的I/O操作次数,理想情况下,最好保持在能保证后台任务不会延迟的较小的值,若设置的过高,数据会太快的从buffer poolinsert buffer中被移除而不能充分发挥缓存的好处,且在实际情况中也没有什么意义。

 

innodb_lock_wait_timeout                 50                                         7200

Command-Line Format

--innodb_lock_wait_timeout=#

System Variable

Name

innodb_lock_wait_timeout

Variable Scope

Global, Session

Dynamic Variable

Yes

Permitted Values

Type

integer

Default

50

Min Value

1

Max Value

1073741824

InnoDB事务等待row lock的超时时间。超时后会回滚当前语句而非整个事务,若想回滚整个事务则还需配置 innodb_rollback_on_timeout 参数。在交互度较高的OLTP应用中可适当降低该值,在需长时间运行的后台操作应用中可适当增加该值。该参数仅适用于row lock

 

innodb_log_buffer_size                   8388608 (8M)                                    67108864 (64M)

Command-Line Format

--innodb_log_buffer_size=#

System Variable

Name

innodb_log_buffer_size

Variable Scope

Global

Dynamic Variable

No

Permitted Values

Type

integer

Default

8388608

Min Value

262144

Max Value

4294967295

InnoDB日志缓冲区的大小。InnoDB按一定策略将日志由缓冲区刷到磁盘上的日志文件。较大的日志缓冲区可以避免较大的事务在提交前因log buffer不足而被迫刷日志到磁盘。因此在具有大的更新、删除、插入事务时增加log buffer可节省磁盘IO

 

innodb_log_file_size                     1073741824   (1G)                              536870912 (512MB)

Command-Line Format

--innodb_log_file_size=#

System Variable

Name

innodb_log_file_size

Variable Scope

Global

Dynamic Variable

No

Permitted Values(<= 5.6.2)

Type

integer

Default

5242880

Min Value

1048576

Max Value

4GB / innodb_log_files_in_group

Permitted Values(>= 5.6.3, <= 5.6.7)

Type

integer

Default

5242880

Min Value

1048576

Max Value

512GB / innodb_log_files_in_group

Permitted Values(>= 5.6.8)

Type

integer

Default

50331648

Min Value

1048576

Max Value

512GB / innodb_log_files_in_group

Log group中每个log file的大小。Log group中日志文件总大小 (innodb_log_file_size * innodb_log_files_in_group)不能超过限制(当前版本是512G)。较合理的值可以为1MB1/N倍的buffer pool size,其中Ninnodb_log_files_in_group。较大的日志文件可以使buffer pool中所需的checkpoint刷新活动减少,从而节省磁盘IO,但较大的日志文件会导致较慢的崩溃恢复速度。

 

innodb_open_files                        300                                        1024

Command-Line Format

--innodb_open_files=#

System Variable

Name

innodb_open_files

Variable Scope

Global

Dynamic Variable

No

Permitted Values(<= 5.6.5)

Type

integer

Default

300

Min Value

10

Max Value

4294967295

Permitted Values(>= 5.6.6)

Type

integer

Default

-1 (autosized)

Min Value

10

Max Value

4294967295

仅当使用了独立InnoDB表空间时该参数才有用,指定了MySQL能够同时打开的.ibd文件个数,仅适用于InnoDB表,独立于 --open-files-limit,且对table cache操作没有影响。

 

innodb_purge_threads                     0                                          1

Command-Line Format

--innodb_purge_threads=#

System Variable

Name

innodb_purge_threads

Variable Scope

Global

Dynamic Variable

No

Permitted Values(<= 5.6.1)

Type

integer

Default

0

Min Value

0

Max Value

1

Permitted Values(>= 5.6.2, <= 5.6.4)

Type

integer

Default

0

Min Value

0

Max Value

32

Permitted Values(>= 5.6.5)

Type

integer

Default

1

Min Value

1

Max Value

32

InnoDB中专门用于purge操作的后台新城数。0值表明purge操作是作为master thread的一部分进行的;非0值表明在一个或者多个后台线程中运行purge操作,有效减少了InnoDB范围内的内部争用,提升可扩展性。

 

interactive_timeout                      28800  8小时                                    3600  1小时

Command-Line Format

--interactive_timeout=#

System Variable

Name

interactive_timeout

Variable Scope

Global, Session

Dynamic Variable

Yes

Permitted Values

Type

integer

Default

28800

Min Value

1

交互式连接上的超时时间,单位为妙。MySQL在等待若干秒后若未接收到交互式客户端上的活动则会关闭连接。

 

join_buffer_size                         134217728   128MB                               131072 128kB

Command-Line Format

--join_buffer_size=#

System Variable

Name

join_buffer_size

Variable Scope

Global, Session

Dynamic Variable

Yes

Permitted Values(Windows, <= 5.6.5)

Type

integer

Default

131072

Min Value

128

Max Value

4294967295

Permitted Values(Windows, >= 5.6.6)

Type

integer

Default

262144

Min Value

128

Max Value

4294967295

Permitted Values(Other, 32-bit platforms, <= 5.6.5)

Type

integer

Default

131072

Min Value

128

Max Value

4294967295

Permitted Values(Other, 32-bit platforms, >= 5.6.6)

Type

integer

Default

262144

Min Value

128

Max Value

4294967295

Permitted Values(Other, 64-bit platforms, <= 5.6.5)

Type

integer

Default

131072

Min Value

128

Max Value

18446744073709547520

Permitted Values(Other, 64-bit platforms, >= 5.6.6)

Type

integer

Default

262144

Min Value

128

Max Value

18446744073709547520

用于索引扫描、范围索引扫描、不能使用索引而走全表扫描的join的最小buffer大小。加速join操作的最好的办法是在join字段上添加索引,如果出于某原因不能添加索引则适当增大join_buffer_size也可获得理想的速度提升。每两个表之间的连接需要一个join buffer,对于一个复杂的,涉及到多个表之间的连接需要多个join buffer。使用该变量要谨慎,因为除非是使用了BKA方法(Batched Key Access),否则将join buffer设置的比所需的过大并没有什么益处,而且还可能造成性能下降。推荐的做法是将全局的join buffer保持在一个较小的值而仅把存在较大的join(多表join)sessionjoin buffer设置的大一点。如果全局的join bufer设置的过大则为每个需要join buffer的查询分配内存时会引起性能的下降。当使用BKA算法时,join buffer的大小决定了每次向存储引擎发起的请求中包含的批量的key的多少,此时,join buffer愈大,就会有越多的连续访问,对性能的提升就越显著。

 

key_buffer_size                          8388608   8MB                                 16777216 16MB

Command-Line Format

--key_buffer_size=#

System Variable

Name

key_buffer_size

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values(32-bit platforms)

Type

integer

Default

8388608

Min Value

8

Max Value

4294967295

Permitted Values(64-bit platforms)

Type

integer

Default

8388608

Min Value

8

Max Value

OS_PER_PROCESS_LIMIT

仅适用于MyISAM表,MyISAM引擎的表其索引独立于数据存储,该变量定义用于缓存MyISAM索引块以供所有线程共享的缓冲区大小。Key buffer也称为key cache。需要知道的是最终分配给key buffer的内存大小可能会少于设定的值,因为会受到系统可用物理内存、进程可用物理内存等限制。设当增加该值可提升所有涉及到索引处理的读操作和多数写操作的性能。在一个主要运行MyISAM引擎的MySQL服务器上可设置该值为总内存的25%,若设置的过大,比如总内存的50%则可能造成系统性能下降。因为MySQL还依赖于操作系统的文件系统缓存,且除了MyISAM外系统上还可能运行有其他的引擎。

 

log_bin_trust_function_creators          OFF                                        ON

Command-Line Format

--log-bin-trust-function-creators

System Variable

Name

log_bin_trust_function_creators

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values

Type

boolean

Default

FALSE

仅当二进制日志启用时该参数才有意义,用于在复制环境中控制用户是否可创建可能导致主从不一致的stored function。若设置为0/FALSE/OFF则用户不允许创建或者更新function除非除了CREATE ROUTINEALTER ROUTINE外还具有super权限而且function必须使用 DETERMINISTICREADS SQL DATA 或 NO SQL进行声明。若设置为1/TRUE/ON则不会有上述限制。

 

max_allowed_packet                       1048576        1MB                                    1073741824        1GB

Command-Line Format

--max_allowed_packet=#

System Variable

Name

max_allowed_packet

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values(<= 5.6.5)

Type

integer

Default

1048576

Min Value

1024

Max Value

1073741824

Permitted Values(>= 5.6.6)

Type

integer

Default

4194304

Min Value

1024

Max Value

1073741824

MySQL所允许的packet或者generated/intermediate string或者任何mysql_stmt_send_long_data() C API函数所发送的参数的最大大小。Packet message buffer最初被初始化为net_buffer_length 大小,之后可增长至 max_allowed_packet ,默认值较小,以便于捕获大的(通常可能是错误的)包。若使用了较大的BLOB字段或者较长的string则要适当调大改参数,该参数需为1024的倍数,否则会被自动调整为最接近的1024倍数。在调整该参数时,除了要调整server端,需要的话可能还要调整client端。需注意的是session范围内的该变量是只读的。

 

max_connect_errors                       1000                                       999999999

Command-Line Format

--max_connect_errors=#

System Variable

Name

max_connect_errors

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values(32-bit platforms, <= 5.6.5)

Type

integer

Default

10

Min Value

1

Max Value

4294967295

Permitted Values(32-bit platforms, >= 5.6.6)

Type

integer

Default

100

Min Value

1

Max Value

4294967295

Permitted Values(64-bit platforms, <= 5.6.5)

Type

integer

Default

10

Min Value

1

Max Value

18446744073709551615

Permitted Values(64-bit platforms, >= 5.6.6)

Type

integer

Default

100

Min Value

1

Max Value

18446744073709551615

所允许的最大连续连接失败次数,如果在达到该次数时仍未成功连接则server会阻止相应的host继续连接,直至通过 FLUSH HOSTS 语句或者mysqladmin flush-hosts 命令刷新host cache。若在连续若干次失败后且在达到最大连续失败次数之前成功连接了一次则之前累计的失败次数会被置零。

 

max_connections                          5000                                       800

Command-Line Format

--max_connections=#

System Variable

Name

max_connections

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values

Type

integer

Default

151

Min Value

1

Max Value

100000

允许的同时连接至server的最大客户端连接数。增大该值会增加mysqld所需的文件描述符数量,若文件描述符数量不足则server会减少max_connections值。如果因为达到了max_connections 的限制而使连接被拒绝则会增加 Connection_errors_max_connections 状态变量的值。

 

max_long_data_size                       1048576                                    1073741824

Introduced

5.5.11

Deprecated

5.5.11

Command-Line Format

--max_long_data_size=#

System Variable

Name

max_long_data_size

Variable Scope

Global

Dynamic Variable

No

Permitted Values

Type

integer

Default

1048576

Min Value

1024

Max Value

4294967295

 mysql_stmt_send_long_data() C API所能发送的最大参数大小。已在MySQL5.6中被移除。由max_allowed_packet参数行使相应功能。

net_buffer_length                        16384                                      8192

Command-Line Format

--net_buffer_length=#

System Variable

Name

net_buffer_length

Variable Scope

Global, Session

Dynamic Variable

Yes

Permitted Values

Type

integer

Default

16384

Min Value

1024

Max Value

1048576

每个client线程都会关联一个connection buffer和一个result buffer,两个buffer都会被初始化为net_buffer_length 指定的大小,并会在需要的时候动态的自动的增大至max_allowed_packet 指定的大小。每个SQL结束后会缩减至net_buffer_length指定的大小。该值通常无需改变,若内存有限可适当调低该值,只在必要的时候使其自动增加。需要注意的是session范围内的该变量为只读变量。

 

open_files_limit                         25000                                      102400

Command-Line Format

--open-files-limit=#

System Variable

Name

open_files_limit

Variable Scope

Global

Dynamic Variable

No

Permitted Values(<= 5.6.7)

Type

integer

Default

0

Min Value

0

Max Value

platform dependent

Permitted Values(>= 5.6.8)

Type

integer

Default

5000, with possible adjustment

Min Value

0

Max Value

platform dependent

操作系统允许mysqld打开的文件数。MySQL Server实际运行时能够打开的最大文件数可能不同于服务器启动时指定的值。在某些系统上MySQL不能改变可打开的文件数,此时该值为0。实际有效的open_files_limit值基于以下三个公式:

1) 10 + max_connections + (table_open_cache * 2)

2) max_connections * 5

3) open_files_limit value specified at startup, 5000 if none

Server试图获取这三个值中最大值表示的文件描述符数,如果获取不到这么多文件描述符则会尽可能多的获取。

 

query_cache_type                         ON                                         OFF

Command-Line Format

--query_cache_type=#

System Variable

Name

query_cache_type

Variable Scope

Global, Session

Dynamic Variable

Yes

Permitted Values(<= 5.6.7)

Type

enumeration

Default

1

Valid Values

0

1

2

Permitted Values(>= 5.6.8)

Type

enumeration

Default

0

Valid Values

0

1

2

设置query cache 类型。0/OFF:不缓存结果或者从缓存中读取结果(注意,这里不缓存结果并不会改变query cache buffer,要关闭query cache buffer需设置 query_cache_buffer 01/ON:缓存除了指明 SELECT SQL_NO_CACHE外的所有查询结果;2/DEMAND:仅缓存指明 SELECT SQL_CACHE的查询结果。)若query_cache_type被设置为0server便不会获取query cache mutex,意味着query cache不被开启,查询执行过程中的开销会减少一点点。

 

read_buffer_size                         131072        128KB                                    262144        256KB

Command-Line Format

--read_buffer_size=#

System Variable

Name

read_buffer_size

Variable Scope

Global, Session

Dynamic Variable

Yes

Permitted Values

Type

integer

Default

131072

Min Value

8200

Max Value

2147479552

每个在MyISAM表上执行连续扫描的线程会分配一个该值指定的大小的buffer。若该类操作较多则可适当增加该值。值需为4KB的整数倍,否则会舍为最接近的4KB的整数倍。该选项也用于其他存储引擎如下一些情形:

排序行时将索引缓存进临时文件、向partitionbulk insert、嵌套查询结果缓存

 

read_only                                ON                                         OFF

Command-Line Format

--read_only

System Variable

Name

read_only

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values

Type

boolean

Default

OFF

开启该变量后server不允许用户进行更新操作除非用户具备super权限。该变量默认关闭。需要注意的是,即便是开启了read only 部分操作还是允许的,比如:

    复制环境下,slave机器上由slave线程执行的更新。这样可以保证slave只接受来自master的更新而不接受来自任何client的更新。

    ANALYZE TABLE 或OPTIMIZE TABLE 语句。read only只阻止对表结构或者内容的更新,analysisoptimization不属于此类变化,这也意味 着可在read onlyslave上使用 mysqlcheck --all-databases --analyze进行一致性检查。

    对临时表的操作。

    对日志表的插入(mysql.general_log和 mysql.slow_log;)

read only 是全局变量,修改该变量需要super权限,在master上修改该变量的值并不会传递到slave上。在试图开启read only时会发生以下情况:

    若已通过LOCK TABLES语句明确的获取了锁或者有处于pending状态的事务则,则开启read only的尝试会失败;

    若其他的client持有显式的表锁或者有pending transactions则开启read only的尝试会被阻塞直至锁被释放或者事务结束;而当正在开启read only 时其他的client在请求表锁或者要开始一个事物则这些动作会被阻塞直至read only被设置好;

    如果存在active状态的事务持有metadata锁则开启read only的请求会被阻塞直至事务结束;

    若是通过FLUSH TABLES WITH READ LOCK获取了全局读锁则开启read only的请求不会被阻塞。


read_rnd_buffer_size                     4194304                                    524288

Command-Line Format

--read_rnd_buffer_size=#

System Variable

Name

read_rnd_buffer_size

Variable Scope

Global, Session

Dynamic Variable

Yes

Permitted Values

Type

integer

Default

262144

Min Value

1

Max Value

2147483647

该变量用于从MyISAM表中读数据,或者用于其它引擎中的Multi-Range ReadMRR)优化(http://dev.mysql.com/doc/refman/5.6/en/mrr-optimization.html)当根据key排序后从MyISAM表顺序读取行时,行会从该buffer中读取以避免磁盘访问。调大该值可以显著提升order by 性能。然而,server会为每个client分配一个指定大小的buffer,因此不能将全局范围的该变量设置过大,否则会造成内存浪费,而应当只为需要运行此类大查询的session单独调大session级别的变量。

 

report_port                              3306                                       20125

Command-Line Format

--report-port=#

System Variable

Name

report_port

Variable Scope

Global

Dynamic Variable

No

Permitted Values(<= 5.6.4)

Type

integer

Default

0

Min Value

0

Max Value

65535

Permitted Values(>= 5.6.5)

Type

integer

Default

[slave_port]

Min Value

0

Max Value

65535

在注册slave时需要让master知道的连接slaveTCP/IP端口号。仅在slave没有使用默认端口时或者从master或其他clientslave有特殊通道时需设置该值。如果不确定,则不用使用该选项。

 

secure_auth                              ON                                         OFF

Command-Line Format

--secure-auth

System Variable

Name

secure_auth

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values(<= 5.6.4)

Type

boolean

Default

OFF

Permitted Values(>= 5.6.5)

Type

boolean

Default

ON

开启该选项后server会阻塞使用旧的密码格式(pre-4.1)的客户端连接,以保障安全。

 

skip_name_resolve                        OFF                                        ON

Command-Line Format

--skip-name-resolve

System Variable

Name

skip_name_resolve

Variable Scope

Global

Dynamic Variable

No

Permitted Values

Type

boolean

Default

OFF

设置为OFF则在检查客户端连接时mysqld会解析host name;设置为ONmysqld不解析host name而仅使用IP地址,此时权限表中的host列必须为IP地址或者localhost,否则不能正确匹配。

 

slave_net_timeout                        120                                        3600

Command-Line Format

--slave-net-timeout=#

System Variable

Name

slave_net_timeout

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values

Type

integer

Default

3600

Min Value

1

MySQL主从复制的时候, 当MasterSlave之间的网络中断,但是MasterSlave无法察觉的情况下(比如防火墙或者路由问题),Slave会等待slave_net_timeout设置的秒数后,才能认为网络出现故障,然后才会重连并且追赶这段时间主库的数据。

 

sort_buffer_size                         4194304                                    524288

Command-Line Format

--sort_buffer_size=#

System Variable

Name

sort_buffer_size

Variable Scope

Global, Session

Dynamic Variable

Yes

Permitted Values(Windows, <= 5.6.3)

Type

integer

Default

2097144

Min Value

32768

Max Value

4294967295

Permitted Values(Windows, >= 5.6.4)

Type

integer

Default

262144

Min Value

32768

Max Value

4294967295

Permitted Values(Other, 32-bit platforms, <= 5.6.3)

Type

integer

Default

2097144

Min Value

32768

Max Value

4294967295

Permitted Values(Other, 32-bit platforms, >= 5.6.4)

Type

integer

Default

262144

Min Value

32768

Max Value

4294967295

Permitted Values(Other, 64-bit platforms, <= 5.6.3)

Type

integer

Default

2097144

Min Value

32768

Max Value

18446744073709551615

Permitted Values(Other, 64-bit platforms, >= 5.6.4)

Type

integer

Default

262144

Min Value

32768

Max Value

18446744073709551615

每个需要排序操作的session会分配一个指定大小的缓冲区。sort_buffer_size不特定于存储引擎而适用于通用的排序优化操作。比如,若状态变量中每秒钟的Sort_merge_passes较多则可考虑增大sort_buffer_size的值来加速ORDER BYGROUP BY操作(若可以通过优化SQL或者添加索引来解决问题则可不用调整该参数)MySQL5.6.4之前优化器会分配整个缓冲区大小的内存即使是不需要这么多的情况下,MySQL5.6.4以后优化器会计算出实际需要的内存,但是会多分一点点直至到达上界。如果把全局范围内的该变量设置过大则可能会使查询变慢,最好的实践是只在需要进行排序需要较大缓冲区的session中调大该变量。Linux系统上存在两个阈值256KB2MB(分别对应5.6.3版本之后和之前版本的默认值),超过这两个阈值则内存分配会显著变慢,最好通过实验测试出合理的值。

 

sql_mode                                 STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION 

 

sync_binlog                              1                                          0

Command-Line Format

--sync-binlog=#

System Variable

Name

sync_binlog

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values(32-bit platforms)

Type

integer

Default

0

Min Value

0

Max Value

4294967295

Permitted Values(64-bit platforms)

Type

integer

Default

0

Min Value

0

Max Value

4294967295

如果该值大于0MySQL Server会在sync_binlog次提交组被写入binary log后将binary log同步到磁盘。若值为0则不主动同步binary log到磁盘而完全依赖于操作系统刷binary log内容到磁盘。设置为1是最安全的选择,可以保证在崩溃后binary log中最多丢失一个提交组,然而这也是最慢的选择(除非磁盘具备 battery-backed cache,此时可以较快的同步)因为每个提交组写入binary都会导致刷binary log到磁盘。

 

table_open_cache                         400                                        64

System Variable

Name

table_open_cache

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values(<= 5.6.7)

Type

integer

Default

400

Min Value

1

Max Value

524288

Permitted Values(>= 5.6.8)

Type

integer

Default

2000

Min Value

1

Max Value

524288

所有threads打开的表数。增加该值会增加mysqld需要的文件描述符数。可通过检查 Opened_tables状态变量确定是否需要增加该值,若状态变量较大且不经常使用flush tables(强制关闭并重新打开所有表)则应该增大table_open_cache 。

 

thread_cache_size                        0                                          32

Command-Line Format

--thread_cache_size=#

System Variable

Name

thread_cache_size

Variable Scope

Global

Dynamic Variable

Yes

Permitted Values(<= 5.6.7)

Type

integer

Default

0

Min Value

0

Max Value

16384

Permitted Values(>= 5.6.8)

Type

integer

Default

-1 (autosized)

Min Value

0

Max Value

16384

Server缓存下来以便复用的线程数。当客户端连接断开后客户端的线程会被放在该cache中(如果尚有空间的话)。如果可能的话,后续的线程请求会直接复用cache中的线程,仅当cache为空时会创建新的线程。如果每秒的新连接非常非常多则适当增加该值可一定程度上提升性能,否则并不会有显著的性能提升。可通过检查Connections Threads_created 状态变量来确定thread cache的效率以决定是否要增减该值。

 

thread_concurrency                       10                                         4

Deprecated

5.6.1

Command-Line Format

--thread_concurrency=#

System Variable

Name

thread_concurrency

Variable Scope

Global

Dynamic Variable

No

Permitted Values

Type

integer

Default

10

Min Value

1

Max Value

512

针对于Solaris 8或更早的系统,使mysqld根据指定的参数调用thr_setconcurrency()函数,以提示线程系统应该同时运行的线程数。在MySQL5.6.1中已降级将在MySQL5.7中移除。

 

thread_stack                             262144    256KB                                  524288 512KB

Command-Line Format

--thread_stack=#

System Variable

Name

thread_stack

Variable Scope

Global

Dynamic Variable

No

Permitted Values(32-bit platforms)

Type

integer

Default

196608

Min Value

131072

Max Value

4294967295

Block Size

1024

Permitted Values(64-bit platforms)

Type

integer

Default

262144

Min Value

131072

Max Value

18446744073709551615

Block Size

1024

线程的stack大小。默认值192KB64位系统是256KB)对于通常的操作已足够大。若该值过小会限制server能够处理的SQL语句的复杂性,存储过程的递归深度和其他消耗内存的操作。

 

tmp_table_size                           16777216  16MB                                 134217728 128MB

Command-Line Format

--tmp_table_size=#

System Variable

Name

tmp_table_size

Variable Scope

Global, Session

Dynamic Variable

Yes

Permitted Values

Type

integer

Default

16777216

Min Value

1024

Max Value

18446744073709551615

内部的内存临时表大小(实际的大小由tmp_table_sizemax_heap_table_size共同确定)。若内存临时表超出限制则会自动转变为MyISAM引擎的磁盘临时表。若查询中会进行大量group by操作,且内存充足则可增大该值(必要时还要增大max_heap_table_size)。需注意的是该值是针对内部临时表的,对于用户自定义的临时表无效。可通过查看 Created_tmp_disk_tables 和 Created_tmp_tables两个状态变量来确定是否需要增加参数值。

 

wait_timeout                             28800                                      432000

Command-Line Format

--wait_timeout=#

System Variable

Name

wait_timeout

Variable Scope

Global, Session

Dynamic Variable

Yes

Permitted Values(Windows)

Type

integer

Default

28800

Min Value

1

Max Value

2147483

Permitted Values(Other)

Type

integer

Default

28800

Min Value

1

Max Value

31536000

非交互式连接上等待事件的超时时间。在该段时间内没有活动信息则会关闭连接。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值