mysql配置选项



[root@localhostmysql]# cat /etc/my.cnf

# Example MySQLconfig file for very large systems.

#

# This is for alarge system with memory of 1G-2G where the system runs mainly

# MySQL.

#

# MySQL programslook for option files in a set of

# locations whichdepend on the deployment platform.

# You can copy thisoption file to one of those

# locations. Forinformati on about these locations, see:

#

# In this file, youcan use all long options that a program supports.

# If you want toknow which options a program supports, run the program

# with the"--help" option.

 

# The followingoptions will be passed to all MySQL clients

[client]

#password      = your_password

port           = 3306

#socket        = /usr/local/mysql/data/mysqld.sock

 

socket         = /data/mysql/data/mysqld.sock

# Here followsentries for some specific programs

 

# The MySQL server

[mysqld]

port           = 3306

socket         = /data/mysql/data/mysqld.sock

basedir=/usr/local/mysql    #--->Mysql安装目录的文件系统中的位置

datadir=/data/mysql/data/  #--->datadir所有数据库、表、InnoDB数据、服务器日志和二进制日志文件等的存储目录

skip-external-locking

key_buffer_size =384M

max_allowed_packet =1212M

table_open_cache =512

sort_buffer_size =20M

read_buffer_size =20M

read_rnd_buffer_size= 80M

myisam_sort_buffer_size= 640M

thread_cache_size =8

query_cache_size =320M

# Try number ofCPU's*2 for thread_concurrency

thread_concurrency =8

key_buffer_size

索引块是缓冲的并且被所有的线程共享。key_buffer_size是用于索引块的缓冲区大小,增加它可得到更好处理的索引(对所有读和多重 写),到你 能负担得起那样多。

 

table_cache_size

设置不立即生效,缓存表的个数

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

innodb_flush_log_at_trx_commit=0

innodb_autoextend_increment=512M

innodb_log_buffer_size=512M

 

wait_timeout=2880000

interactive_timeout= 2880000

 

 

# Don't listen on aTCP/IP port at all. This can be a security enhancement,

# if all processesthat need to connect to mysqld run on the same host.

# All interactionwith mysqld must be made via Unix sockets or named pipes.

# Note that usingthis option without enabling named pipes on Windows

# (via the"enable-named-pipe" option) will render mysqld useless!

#

#skip-networking

 

# Replication MasterServer (default)

# binary logging isrequired for replication

#log-bin=mysql-bin

 

# required unique idbetween 1 and 2^32 - 1

# defaults to 1 ifmaster-host is not set

# but will notfunction as a master if omitted

server-id      = 1

 

# Replication Slave(comment out master section to use this)

#

# To configure thishost as a replication slave, you can choose between

# two methods :

#

# 1) Use the CHANGEMASTER TO command (fully described in our manual) -

#    the syntax is:

#

#    CHANGE MASTER TO MASTER_HOST=<host>,MASTER_PORT=<port>,

#    MASTER_USER=<user>,MASTER_PASSWORD=<password> ;

#

#    where you replace <host>,<user>, <password> by quoted strings and

#    <port> by the master's port number(3306 by default).

#

#    Example:

#

#    CHANGE MASTER TOMASTER_HOST='125.564.12.1', MASTER_PORT=3306,

#    MASTER_USER='joe',MASTER_PASSWORD='secret';

#

# OR

#

# 2) Set thevariables below. However, in case you choose this method, then

#    start replication for the first time (evenunsuccessfully, for example

#    if you mistyped the password inmaster-password and the slave fails to

#    connect), the slave will create amaster.info file, and any later

#    change in this file to the variables'values below will be ignored and

#    overridden by the content of themaster.info file, unless you shutdown

#    the slave server, delete master.info andrestart the slaver server.

#    For that reason, you may want to leave thelines below untouched

#    (commented) and instead use CHANGE MASTERTO (see above)

#

# required unique idbetween 2 and 2^32 - 1

# (and differentfrom the master)

# defaults to 2 ifmaster-host is set

# but will notfunction as a slave if omitted

#server-id      = 2

#

# The replicationmaster for this slave - required

#master-host    =  <hostname>

#

# The username theslave will use for authentication when connecting

# to the master -required

#master-user    =  <username>

#

# The password theslave will authenticate with when connecting to

# the master -required

#master-password=  <password>

#

# The port themaster is listening on.

# optional -defaults to 3306

#master-port    = <port>

#

# binary logging -not required for slaves, but recommended

#log-bin=mysql-bin

#

# binary loggingformat - mixed recommended

#binlog_format=mixed

 

innodb_file_per_table

当它被激活时,所有innoDB存储引擎的表都将创建自己的表空间.

t_p_rooms_get_20131206.frm【】

t_p_rooms_get_20131206.ibd【数据和索引存放的地方】

-->tablename.ibd

 

# Uncomment thefollowing if you are using InnoDB tables

#innodb_data_home_dir= /usr/local/mysql

innodb_data_home_dir

默认值是系统的datadir.

未用innodb_data_file_path没使用绝对路径来确定共享的表空间。

可使用它来指定所有普通的innoDB数据文件在os上的路径。

#innodb_data_file_path= ibdata1:2000M;ibdata2:10M:autoextend

innodb_data_file_path

确定单个InnoDB数据文件的位置以及他们的大小和行为

#innodb_log_group_home_dir= /usr/local/mysql

# You can set.._buffer_pool_size up to 50 - 80 %

# of RAM but bewareof setting memory usage too high

#innodb_buffer_pool_size= 384M

#innodb_additional_mem_pool_size= 20M

# Set.._log_file_size to 25 % of buffer pool size

#innodb_log_file_size= 100M

#innodb_log_buffer_size= 8M

#innodb_flush_log_at_trx_commit= 1

#innodb_lock_wait_timeout= 50

 

[mysqldump]

quick

max_allowed_packet =16M

 

[mysql]

no-auto-rehash

# Remove the nextcomment character if you are not familiar with SQL

#safe-updates

 

[myisamchk]

key_buffer_size =256M

sort_buffer_size =256M

read_buffer = 2M

write_buffer = 2M

 

[mysqlhotcopy]

interactive-timeout

 

sync_binlog

“sync_binlog”:这个参数是对于MySQL系统来说是至关重要的,他不仅影响到Binlog对MySQL所带来的性能损耗,而且还影响到MySQL中数据的完整性。对于“sync_binlog”参数的各种设置的说明如下:

sync_binlog=0,当事务提交之后,MySQL不做fsync之类的磁盘同步指令刷新binlog_cache中的信息到磁盘,而让Filesystem自行决定什么时候来做同步,或者cache满了之后才同步到磁盘。

sync_binlog=n,当每进行n次事务提交之后,MySQL将进行一次fsync之类的磁盘同步指令来将binlog_cache中的数据强制写入磁盘。

MySQL中系统默认的设置是sync_binlog=0,也就是不做任何强制性的磁盘刷新指令,这时候的性能是最好的,但是风险也是最大的。因为一旦系统Crash,在binlog_cache中的所有binlog信息都会被丢失。而当设置为“1”的时候,是最安全但是性能损耗最大的设置。因为当设置为1的时候,即使系统Crash,也最多丢失binlog_cache中未完成的一个事务,对实际数据没有任何实质性影响。从以往经验和相关测试来看,对于高并发事务的系统来说,“sync_binlog”设置为0和设置为1的系统写入性能差距可能高达5倍甚至更多.

innodb_flush_log_at_trx_commit

[0,1,2]

0会更快一点,但安全方面比较差,即使MySQL挂了也可能会丢失事务的数据

1默认每次提交后把日志缓冲区的内容写到InnoDB日志文件中【最为影响性能之一
2
将以每秒一次的松散间隔将日志缓冲区中的内容写到InnoDB日志文件中

innodb_support_xa
 

[OFF,ON]

ON

OFF

Innodb_doublewrite

 

 

 

 

 

 

 

 

 

--下面的参数我使用的事my-huge.cnf

max_connections

最大并发连接数。当MySQL的并发连接达到这个设定值时,新的连接将会被拒绝。

当发现MySQL有能力处理更多的并发的时候,

建议调大这个值,相应给服务器带来更高的负载(CPU/IO/内存)

默认值:100

参考设置:900

配置参考:Max_used_connections-->SHOW GLOBAL STATUS

back_log

TCP/IP连接队列的最大值。当MySQL同时有大量连接请求的时候,MySQL会尝试用当前现有的线程处理这些请求,如果处理不过来,MySQL会把连接先放到一个队列里面,然后起新的线程处理。这个过程会很快, 但是并发请求很多的话,需要调高这个值,否则新来的连接请求会被拒绝。在一次压测的时候发现客户端返回大量的“Lost connection to MySQL”, 就是因为back_log的默认值太小导致的。增大这个值会增大CPU负载并消耗更多的内存。

默认值:80,

参考设置:200

 

skip_name_resolve

关闭反向域名解析。MySQL默认会对每个客户端连接作反向域名解析,强烈建议关闭反向域名解析。关闭的方法是在my.cnf里面加一行skip-name-resolve

强烈建议关闭

 

innodb_file_per_table

如果使用innodb,强烈建议打开这个设置,否则所有的innodb表共享一个文件,并且这个文件的大小不会因为表数据的减少而减小,时间长了会把磁盘搞爆,这是mysql的一个bughttp://bugs.mysql.com/bug.php?id=1341

默认为ON

 

max_connect_errors

当客户端连接服务端超时(超过connect_timeout),服务端就会给这个客户端记录一次error,当出错的次数达到max_connect_errors的时候,这个客户端就会被锁定。除非执行FLUSH HOSTS命令。绝对是个地雷!

默认值:10参考设置:65535(最大值了)(能设多大,设多大)

 

connect_timeout

连接超时的秒数。

默认值:5参考设置:15

 

slave_net_timeout

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

默认值:3600参考设置:30

 

interactive_timeout

参数含义:服务器关闭交互式连接前等待活动的秒数。交互式客户端定义为在mysql_real_connect()中使用CLIENT_INTERACTIVE选项的客户端。

参数默认值:28800秒(8小时)

 

wait_timeout

连接过期秒数。当一个连接SLEEP超过wait_timeout秒后,MySQL服务端会中断这个连接。这个值设置的过长有可能会导致大量的SLEEP链接占用系统资源,过小会导致“MySQL has gone away”的错误。
MySQL服务器所支持的最大连接数是有上限的,因为每个连接的建立都会消耗内存,因此我们希望客户端在连接到
MySQL Server处理完相应的操作后,应该断开连接并释放占用的内存。如果你的MySQL Server有大量的闲置连接,他们不仅会白白消耗内存,而且如果连接一直在累加而不断开,最终肯定会达到MySQL Server的连接上限数,这会报'too many connections'的错误。对于wait_timeout的值设定,应该根据系统的运行情况来判断。在系统运行一段时间后,可以通过show processlist命令查看当前系统的连接状态,如果发现有大量的sleep状态的连接进程,则说明该参数设置的过大,可以进行适当的调整小些。
 

默认值:28800, 参考设置:30
 

查询资料后,要同时设置interactive_timeout和wait_timeout才会生效。

 

key_buffer

主键缓存。如果发现有大量的slow log,可以尝试调高这个值,相应会带来更高的内存开销。

 

 

table_cache

给经常访问的表分配的内存。调大这个值,一般情况下可以降低磁盘IO,但是相应会占用更多的内存。

 

 

thread_cache_size

服务器线程缓存这个值表示可以重新利用保存在缓存中线程的数量,当断开连接时如果缓存中还有空间,那么客户端的线程将被放到缓存中,如果线程重新被请求,那么请求将从缓存中读取,如果缓存中是空的或者是新的请求,那么这个线程将被重新创建,如果有很多新的线程,增加这个值可以改善系统性能.通过比较 Connections Threads_created状态的变量,可以看到这个变量的作用

Default:8

配置参考:Threads_connectedThreads_createdThreads_cached 他们3的状态-->SHOW GLOBAL STATUS

可以不断刷新,如果 Threads_created 不断增大,那么当前值设置要改大,改到 Threads_connected 值左右,

再结合物理内存 1G —> 8;2G —> 16; 3G —> 32; >3G —> 64 二个情况综合考虑一下值。

Slow_launch_threads该值变大意味着某些情况延迟了连接分配新线程。可能是系统过载,应诊断。

table_cache_size[5.6-5.5我发现没有]

table_open_cache

设置不立即生效,缓存表的个数

Default:512 

配置参考:Open_table_definitions ; Open_tables

-->SHOW GLOBAL STATUS

有些类型的工作负载是不能缓存的,就设置成为0

缓存不命中比进行了昂贵的缓存检查后不命中更好吧。比如表数目及其多几万or几十万表,均匀使用就不缓存为好。参考:

max_connections*10 <10000

expire_logs_days

指定天数后的二进制日志进行清理

Default:0

 

max_allowed_packet

防止服务器发送太大的包,也会控制多大包可以被接受

Default:1048576

 

sql_mode

 

Default:STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION

 

innodb_read_only

read_only 

 

 

备库设置

tmp_table_size

max_heap_table_size

这两个设置控制使用Memory引擎的内存临时表能使用多大的内存.

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值