手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

MySQL 5.5.32 配置文件优化详解

[日期:2013-07-28] 来源:Linux社区  作者:freeloda [字体:大 中 小]

三、配置文件优化(根据实际情况优化)

说明,上文中我对my-innodb-heavy-4G.cnf中默认的所有选项进行了说明,下面我就根据我们公司的实际情况进行优化!

1.服务器的运行环境

  • 硬件服务器:Dell R710,双至强E5620 CPU、16G内存、6*500G硬盘

  • 操作系统:CentOS5.5 X86_64 系统

  • MySQL版本:MySQL 5.5.32

  • 适用于:日IP 100-200W ,日PV 200-500W 的站点

2.具体优化配置如下

[client] 
port        = 3306 
socket        = /tmp/mysql.sock
default-character-set = utf8 #设置客户端的字符编码
[mysqld]
# generic configuration options 
port        = 3306 
socket        = /tmp/mysql.sock
#*** char set ***
character-set-server = utf8 #设置服务器端的字符编码
                       
#*** network ***
back_log = 512
#skip-networking #默认没有开启
max_connections = 3000
max_connect_errors = 30
table_open_cache = 4096
#external-locking #默认没有开启
max_allowed_packet = 32M
max_heap_table_size = 128 M
                       
# *** global cache ***
read_buffer_size = 8M
read_rnd_buffer_size = 64M
sort_buffer_size = 16M
join_buffer_size = 16M
                       
# *** thread ***
thread_cache_size = 16
thread_concurrency = 8
thread_stack = 512K
                       
# *** query  cache ***
query_cache_size = 128M
query_cache_limit = 4M
                       
# *** index ***
ft_min_word_len = 8
                       
#memlock #默认没有开启
default-storage-engine = INNODB
transaction_isolation = REPEATABLE-READ
                       
# *** tmp table ***
tmp_table_size = 64M
                       
# *** 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
key_buffer_size = 128M
bulk_insert_buffer_size = 256M
myisam_sort_buffer_size = 256M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
                       
# *** INNODB Specific options ***
#skip-innodb #默认没有开启
innodb_additional_mem_pool_size = 64M
innodb_buffer_pool_size = 6G #注意在32位系统上你每个进程可能被限制在 2-3.5G 用户层面内存限制, 所以不要设置的太高.
innodb_data_file_path = ibdata1:10M:autoextend
#innodb_data_home_dir = <directory>
innodb_write_io_threads = 8 
innodb_read_io_threads = 8
#innodb_force_recovery=1
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
#说明:innodb_flush_log_at_trx_commit = 2 如果是游戏服务器,建议此值设置为2;如果是对数据安全要求极高的应用,建议设置为1;设置为0性能最高,但如果发生故障,数据可能会有丢失的危险!默认值1的意思是每一次事务提交或事务外的指令都需要把日志写入(flush)硬盘,这是很费时的。特别是使用电池供电缓存(Battery backed up cache)时。设成2对于很多运用,特别是从MyISAM表转过来的是可以的,它的意思是不写入硬盘而是写入系统缓存。日志仍然会每秒flush到硬盘,所以你一般不会丢失超过1-2秒的更新。设成0会更快一点,但安全方面比较差,即使MySQL挂了也可能会丢失事务的数据。而值2只会在整个操作系统挂了时才可能丢数据。
#innodb_fast_shutdown
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
#innodb_log_group_home_dir
innodb_max_dirty_pages_pct = 90
#innodb_flush_method=O_DSYNC
innodb_lock_wait_timeout = 120
[mysqldump] 
quick
max_allowed_packet = 32M
[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

3.总结

MySQL 配置文件的优化是根据线上环境的实际需要进行优化,不能随便没有根据的进行优化,写这篇博文就是给博友们一些参考!

4.MySQL状态查看的常用命令

1
2
3
4
mysql> show status; #显示状态信息
mysql> show variables; #显示系统变量
mysql> show engines; #查看所有引擎
mysql> show engine innodb status; #显示InnoDB存储引擎的状态
linux
相关资讯       MySQL配置优化  MySQL 5.5.32  MySQL配置详解 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款