导读 | 参照 腾讯云 和ucloud my.cnf 以及网上找的资料 整理出来的 my.cnf , 以后修改任何参数都会继续更新 也是在测试阶段 |
物理机 : ubuntu14.04 配置 8core 32G
mysql : 5.5.62
调优配置
[client] port = 3306 socket = /var/run/mysqld/mysqld.sock default-character-set = utf8 [mysqld_safe] socket = /var/run/mysqld/mysqld.sock [mysqld] user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking key_buffer = 256M max_allowed_packet = 1073741824 thread_stack = 512K thread_cache_size = 50 max_connections = 5000 max_connect_errors = 1000000 table_cache = 4096 max_heap_table_size = 128M open_files_limit = 102400 back_log = 2000 thread_concurrency = 20 sort_buffer_size = 524288 ft_min_word_len = 4 query_cache_size = 0 log_error = /var/log/mysql/error.log log_slow_queries = /var/log/mysql/mysql-slow.log long_query_time = 3 server-id = 1 log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 2 tmp_table_size = 4294967295 #default_table_type = InnoDB #loose-skip-bdb default-storage-engine =InnoDB innodb_file_format=barracuda #ROW_FORMAT=COMPRESSED innodb_additional_mem_pool_size = 64M innodb_buffer_pool_size = 6G innodb_data_file_path = ibdata1:128M:autoextend innodb_read_io_threads = 8 innodb_write_io_threads = 8 innodb_thread_concurrency = 20 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 8388608 innodb_log_file_size = 512M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 [mysqldump] quick quote-names max_allowed_packet = 1073741824 [mysql] default-character-set = utf8 [isamchk] key_buffer = 256M !includedir /etc/mysql/conf.d/
附一些参数的简单解释
# The MySQL database server configuration file. # # You can copy this to one of: # - "/etc/mysql/my.cnf" to set global options, # - "~/.my.cnf" to set user-specific options. # # One can use all long options that the program supports. # Run program with --help to get a list of available options and with # --print-defaults to see which it would actually understand and use. # # For explanations see # //dev.mysql.com/doc/mysql/en/server-system-variables.html # This will be passed to all mysql clients # It has been reported that passwords should be enclosed with ticks/quotes # escpecially if they contain "#" chars... # Remember to edit /etc/mysql/debian.cnf when changing the socket location. [client] port = 3306 socket = /var/run/mysqld/mysqld.sock # Here is entries for some specific programs # The following values assume you have at least 32M ram # This was formally known as [safe_mysqld]. Both versions are currently parsed. [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 open-files-limit = 8192 #增加每个进程的可打开文件数量 [mysqld] # # * Basic Settings # user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp #记录msyql临时文件 #back_log = 300 lc-messages-dir = /usr/share/mysql skip-external-locking #允许外部文件级别的锁. 打开文件锁会对性能造成负面影响 # # Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. #bind-address = 0.0.0.0 #控制可连接数据库的 客户端 # # * Fine Tuning # key_buffer = 16M #可变大 待查询 用于索引块缓冲区大小 max_allowed_packet = 16M thread_stack = 192K #线程使用的堆大小. 此容量的内存在每次连接时被预留 thread_cache_size = 8 #cache中保留多少线程用于重用 # This replaces the startup script and checks MyISAM tables if needed # the first time they are touched myisam-recover = BACKUP max_connections = 100 #mysql 允许 同时会话的上限 max_connect_errors = 30 #mysql 允许最大的错误连接上限 table_cache = 64 #mysql所有线程打开表的数量 ,需对应的open_files_limit 允许 max_heap_table_size = 128M #独立的内存表所允许的最大容量(防止意外创建一个超大的内存表导致用尽所有的内存资源) open_files_limit = 10240 #mysql允许打开最大文件数 back_log = 300 #操作系统在监听队列中所保持的连接数 thread_concurrency = 10 #应用程序给予线程系统一个提示在同一时间给予渴望被运行的线程的数量 # # * Query Cache Configuration # sort_buffer_size = 16M #排序发生时每个线程分配 join_buffer_size = 16M #当全联合发生时,在每个线程中分配 query_cache_limit = 1M #只有小于此设定值的结果才会被缓冲 query_cache_size = 16M #查询缓冲常被用来缓冲 SELECT 的结果并且在下一次同样查询的时候不再执行直接返回结果 ft_min_word_len = 8 #被全文检索索引的最小的字长 #memlock #如果你的系统支持 memlock() 函数,你也许希望打开此选项用以让运行中的mysql在在内存高度紧张的时候,数据在内存中保持锁定并且防止可能被swapping out # # * Logging and Replication # # Both location gets rotated by the cronjob. # Be aware that this log type is a performance killer. # As of 5.1 you can enable the log at runtime! #general_log_file = /var/log/mysql/mysql.log #general_log = 1 # # Error log - should be very few entries. # #log #打开全查询日志. 所有的由服务器接收到的查询 (甚至对于一个错误语法的查询) 用于调试环境 #log_warnings #将警告打印输出到错误log文件 log_error = /var/log/mysql/error.log # Here you can see queries with especially long duration log_slow_queries = /var/log/mysql/mysql-slow.log #开启慢日志 long_query_time = 2 #慢日志时间界限 log_long_format #在慢速日志中记录更多的信息 #log-queries-not-using-indexes # # The following can be used as easy to replay backup logs or for replication. # note: if you are setting up a replication slave, see README.Debian about # other settings you may need to change. server-id = 1 #主从id log_bin = /var/log/mysql/mysql-bin.log #开启二进制 expire_logs_days = 10 max_binlog_size = 100M binlog_cache_size = 4M #在一个事务中binlog 为了记录sql状态所持有的cache大小 #binlog_do_db = include_database_name #binlog_ignore_db = include_database_name log_slave_updates #主从日志 # # * InnoDB # # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. # Read the manual for more InnoDB related options. There are many! default_table_type = MYISAM #当创建新表时作为默认使用的表类型, transaction_isolation = REPEATABLE-READ #设定默认的事务隔离级别.可用的级别如下: READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE tmp_table_size = 128M #内部(内存中)临时表的最大大小 # # * Security Features # # Read the manual, too, if you want chroot! # chroot = /var/lib/mysql/ # # For generating SSL certificates I recommend the OpenSSL GUI "tinyca". # # ssl-ca=/etc/mysql/cacert.pem # ssl-cert=/etc/mysql/server-cert.pem # ssl-key=/etc/mysql/server-key.pem # MyISAM 相关选项 #read_buffer_size = 8M #用来做MyISAM表全表扫描的缓冲大小 #read_rnd_buffer_size = 64M #当在排序之后,从一个已经排序好的序列中读取行时,行数据将从这个缓冲中读取来防止磁盘寻道 #bulk_insert_buffer_size = 256M #MyISAM 使用特殊的类似树的cache来使得突发插入 #myisam_sort_buffer_size = 256M #此缓冲当MySQL需要在 REPAIR, OPTIMIZE, ALTER 以及 LOAD DATA INFILE 到一个空表中引起重建索引时被分配. #myisam_max_sort_file_size = 10G #MySQL重建索引时所允许的最大临时文件的大小 (当 REPAIR, ALTER TABLE 或者 LOAD DATA INFILE). #myisam_max_extra_sort_file_size = 10G #如果被用来更快的索引创建索引所使用临时文件大于制定的值,那就使用键值缓冲方法. #myisam_repair_threads = 1 #如果一个表拥有超过一个索引, MyISAM 可以通过并行排序使用超过一个线程去修复他们 #myisam_recover #自动检查和修复没有适当关闭的 MyISAM 表 #INNODB 相关选项 #skip-innodb #如果你的MySQL服务包含InnoDB支持但是并不打算使用的话, #innodb_additional_mem_pool_size = 64M #附加的内存池被InnoDB用来保存 metadata 信息 #innodb_buffer_pool_size = 6G #InnoDB使用一个缓冲池来保存索引和原始数据, 不像 MyISAM #innodb_data_file_path = ibdata1:10M:autoextend #InnoDB 将数据保存在一个或者多个数据文件中成为表空间 #innodb_data_home_dir = #设置此选项如果你希望InnoDB表空间文件被保存在其他分区 #innodb_file_io_threads = 4 #用来同步IO操作的IO线程的数量. #innodb_force_recovery=1 #如果你发现InnoDB表空间损坏, 设置此值为一个非零值可能帮助你导出你的表 #innodb_thread_concurrency = 16 #在InnoDb核心内的允许线程数量 #innodb_flush_log_at_trx_commit = 2 #如果设置为1 ,InnoDB会在每次提交后刷新(fsync)事务日志到磁盘上 如果是游戏服务器,建议此值设置为2;如果是对数据安全要求极高的应用,建议设置为1 #innodb_fast_shutdown #加速InnoDB的关闭. 这会阻止InnoDB在关闭时做全清除以及插入缓冲合并. #innodb_log_buffer_size = 16M #用来缓冲日志数据的缓冲区的大小. #innodb_log_file_size = 512M #在日志组中每个日志文件的大小. #innodb_log_files_in_group = 3 #在日志组中的文件总数. #innodb_log_group_home_dir #InnoDB的日志文件所在位置. 默认是MySQL的datadir #innodb_max_dirty_pages_pct = 90 #在InnoDB缓冲池中最大允许的脏页面的比例. #innodb_flush_method=O_DSYNC #InnoDB用来刷新日志的方法 表空间总是使用双重写入刷新方法 # 默认值是 “fdatasync”, 另一个是 “O_DSYNC” #innodb_lock_wait_timeout = 120 #在被回滚前,一个InnoDB的事务应该等待一个锁被批准多久 [mysqldump] quick quote-names max_allowed_packet = 16M ## 服务所能处理的请求包的最大大小以及服务所能处理的最大的请求大小(当与大的BLOB字段一起工作时相当必要) #safe-updates #仅仅允许使用键值的 UPDATEs 和 DELETEs [mysql] #no-auto-rehash # faster start of mysql but no tab completition [isamchk] key_buffer = 16M sort_buffer_size = 2048M read_buffer = 32M write_buffer = 32M # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. # [myisamchk] key_buffer = 2048M sort_buffer_size = 2048M read_buffer = 32M write_buffer = 32M [mysqlhotcopy] interactive-timeout !includedir /etc/mysql/conf.d/
原文来自:
本文地址://q13zd.cn/enterprise-mysql5-5-tuning.html编辑:public,审核员:逄增宝
Linux大全:
Linux系统大全: