MySQL 5.6 my.cnf 模版



[client] port
= 3306 socket = /var/run/mysqld/mysqld.sock [mysqld_safe] thp-setting=never socket = /var/run/mysqld/mysqld.sock nice = 0 [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 local-infile = 0 lc-messages-dir = /usr/share/mysql skip-external-locking skip-name-resolve #bind-address = 127.0.0.1 #對timestamp新的行為控制參數,相關文章 explicit_defaults_for_timestamp = 1 character-set-server = utf8mb4 default-storage-engine=INNODB ##thread相關參數:Thread_pool_size X Thread_pool_oversubscribe = MySQL內部同時支持運行的最大任務數,相關文章 #MySQL線程調度方式, thread_handling = pool-of-threads #根據系統的CPU創建出thread_pool_size(該參數不建議調整)threadpool中group數量,默認為cpu核心數,server啟動時自動計算 #thread_pool_size = auto #每個thread_pool_size里同時可以運行多少個任務,超過限制后,繼續創建worker線程會被延遲 thread_pool_oversubscribe = 20 #timer線程檢測間隔,單位為毫秒,用於防止thread pool里的線程死掉.Thread pool里線程如果超過thread_pool_stall_limit聲明的時間沒響應降會重新創建 thread_pool_stall_limit = 50 #用於聲明extra_port最大允許的連接,extra_port 去監聽一個和服務端口不一樣的端口,用於Thread pool被占滿或是被鎖着的情況下用於管理使用. extra_max_connection = 5 #線程池的優先級:transactions:使用優先隊列和普通隊列,對於事務已經開啟的statement,放到優先隊列中,否則放到普通隊列中。statements:只使用優先隊列 ;none: 只是用普通隊列,本質上和statements相同,都是只是用一個隊列 thread_pool_high_prio_mode = transactions #當開啟了優先隊列模式后,每個連接最多允許thread_pool_high_prio_tickets次被放到優先隊列中,之后放到普通隊列中 thread_pool_high_prio_tickets=4294967295 #線程最大空閑時間,單位為秒,超過限制后會退出,默認60 thread_pool_idle_timeout=60 #threadpool中最大線程數目,線程總數超過該限制后不能繼續創建更多線程 thread_pool_max_threads = 100000 #FullText #MyISAM ft_min_word_len = 1 ft_max_word_len = 84 #InnoDB innodb_ft_min_token_size= 1 innodb_ft_max_token_size=84 #MyISAM 停止詞存放在文件 ft_stopword_file = /var/lib/mysql/stopword.txt #InnoDB,停止詞存放在表 innodb_ft_server_stopword_table = dba_test/ft_stopwords innodb_ft_user_stopword_table = dba_test/ft_stopwords #控制在創建臨時表時使用的存儲引擎,默認為innodb default_tmp_storage_engine = innodb #線上可以開啟 innodb_undo_directory = /var/lib/mysql/undolog/ innodb_undo_tablespaces = 8 innodb_undo_logs = 128 #用於優化in(),以確認是否直接使用索引統計,相關文章 eq_range_index_dive_limit = 200 #back_log = 500 thread_stack = 192K max_allowed_packet = 32M max_connections = 600 max_connect_errors = 2000 max_heap_table_size = 256M max_length_for_sort_data= 2048 tmp_table_size = 256M read_buffer_size = 512K read_rnd_buffer_size = 1M sort_buffer_size = 512K join_buffer_size = 256K table_open_cache = 1024 #對table cache進行划分,減少table cache的鎖競爭,累死innodb_buffer_poll_instances table_open_cache_instances = 8 thread_cache_size = 64 # * Query Cache Configuration #query_cache_type = 0 #query_cache_size = 0M #query_cache_limit = 1M open_files_limit = 5000 # * Logging and Replication log_error = /var/log/mysql/error_3306.log #開啟慢查詢日志,相關文章1文章2 slow_query_log = 1 slow_query_log_file = /var/log/mysql/mysql-slow.log long_query_time = 0.5 #log-queries-not-using-indexes #general_log = 1 #慢查詢過濾器,用於Percona,相關文章 #log_slow_filter = 'string' #可用值session or query log_slow_rate_type = session #記錄每個session/query的日志,如果log_slow_rate_type為session,將不記錄replication thread的日志 log_slow_rate_limit = 1 #語句執行存儲過程(不包括觸發器)慢將記錄到慢查詢日志 log_slow_sp_statements = 1 #指定慢查詢日志包含多少信息,相關文章 #log_slow_verbosity = '' #每個慢查詢記錄時間戳 #slow_query_log_timestamp_always #精度為second或microsecond slow_query_log_timestamp_precision=second #該變量控制最大slow文件數量,設置slow_query_log_file為沒有.log后綴的文件 #max_slowlog_files #超過該值,slow日志將自動旋轉,生成slow_query_log_file.000001這樣的文件 #max_slowlog_size log_bin = mysql-bin-3306.log binlog_cache_size = 1M max_binlog_size = 1024M binlog_format = MIXED #binlog_format = ROW #binlog_row_image = minimal
#binlog_rows_query_log_events = 1 sync_binlog
= 1000 expire_logs_days = 5
#binlog_checksum = NONE
#事務提交順序和binlog記錄順序是相同的,默認打開
binlog_order_commits    =1
server-id = 10 relay_log = mysqld-relay-bin # * TokuDB tokudb_cache_size = 512M tokudb_commit_sync = 0 tokudb_fsync_log_period = 1000 tokudb_data_dir = /var/lib/mysql/tokudb_data tokudb_log_dir = /var/lib/mysql/tokudb_log tokudb_tmp_dir = /tmp # * MyISAM key_buffer_size = 128M bulk_insert_buffer_size = 8M concurrent_insert = 2 #myisam-recover = BACKUP myisam_recover_options = BACKUP # * InnoDB #打印死鎖到errorlog innodb_print_all_deadlocks = 1

  #預讀,對於隨機讀寫,推薦關閉
  innodb_read_ahead_threshold = 0

#預熱 innodb_buffer_pool_dump_now = 1 innodb_buffer_pool_load_now = 1 innodb_buffer_pool_dump_at_shutdown = 1 innodb_buffer_pool_load_at_startup = 1 #預熱文件 innodb_buffer_pool_filename = ib_buffer_pool

  #事務日志記錄的大小,默認512,ssd可以設置4096
  innodb_log_block_size = 4096

innodb_page_size = 16K #innodb_page_size = 4K #ssd #innodb_flush_neighbors = 0 #ssd innodb_flush_neighbors = 0 #影響page cleaner 線程一次掃描LRU/UNZIP_LRU的深度,默認為1024,IO能力強的可以適當調大。 innodb_io_capacity/innodb_buffer_pool_instances innodb_lru_scan_depth =2000 innodb_strict_mode = 1 innodb_buffer_pool_size = 10000M innodb_buffer_pool_instances = 3 innodb_change_buffering = all innodb_change_buffer_max_size = 20 innodb_autoextend_increment = 64 innodb_additional_mem_pool_size = 15M#5.7中移除,innodb_use_sys_malloc 配置為 ON 時,innodb_additional_mem_pool_size 失效(直接從操作系統分配內存) innodb_file_per_table = 1 innodb_flush_log_at_trx_commit = 2 #自定義刷新日志時間,每隔這么多秒刷一次日志,只有在innodb_flush_log_at_trx_commit=2時才生效
innodb_flush_log_at_timeout
= 3 innodb_log_buffer_size = 8M innodb_log_file_size = 256M innodb_log_files_in_group = 2 innodb_max_dirty_pages_pct = 60 innodb_read_io_threads = 8 innodb_write_io_threads = 8 #innodb_io_capacity = 800 innodb_io_capacity = 2000 #ssd #innodb_io_capacity_max = 2000 innodb_adaptive_flushing = 1 innodb_adaptive_flushing_lwm = 15 innodb_old_blocks_pct = 20 innodb_old_blocks_time = 1000 #online ddl時並發DML產生的row log最大size,超過這個限制會導致DDL回滾 innodb_online_alter_log_max_size = 128M innodb_flush_neighbors = 1 innodb_concurrency_tickets = 5000 innodb_optimize_fulltext_only = 0 innodb_use_native_aio = 1 innodb_use_sys_malloc = 1#innodb_use_sys_malloc 配置為 ON 時,innodb_additional_mem_pool_size 失效(直接從操作系統分配內存)。5.7中移除 innodb_thread_concurrency = 0#回收undo線程 innodb_purge_threads= 4 #5.7 #innodb_page_cleaners = 4
#每次回收undo頁的數量 innodb_purge_batch_size = 300 #創建索引做merge-sort時,一個歸並block的大小 innodb_sort_buffer_size = 16M innodb_change_buffering = all #changebuffer占用bp的最大比例 innodb_change_buffer_max_size = 20 innodb_file_format = barracuda innodb_file_format_check = 1 innodb_file_format_max = barracuda innodb_stats_on_metadata = 0 innodb_open_files = 3000 #Percona支持ALL_O_DIRECT innodb_flush_method = ALL_O_DIRECT #innodb_flush_method = O_DIRECT_NO_FSYNC lock_wait_timeout = 50 transaction-isolation = READ-COMMITTED # * replication replicate-ignore-db = test replicate-ignore-db = mysql #binlog_do_db = include_database_name skip-slave-start = 1 log_slave_updates = 1 #gtid-mode=on # GTID only #enforce-gtid-consistency=true # GTID only master_info_repository = table relay_log_info_repository = table # * slave #並行復制線程數 slave_parallel_workers = 4 #多線程復制需要關閉 slave_transaction_retries = 0 #在並發復制時總共執行這么多次事務后做一次checkpoint,更新show slave status的數據 slave_checkpoint_group = 512 #在復制執行這么長時間后做一次checkpoint slave_checkpoint_period = 300 #在多線程復制時,在隊列中Pending的事件所占用的最大內存,默認為16M,如果內存富余,或者延遲較大時,可以適當調大;注意這個值要比主庫的max_allowed_packet大 slave_pending_jobs_size_max = 32M #備庫SQL線程是否檢查binlog的checksum slave_sql_verify_checksum = 1 #部分解決無主鍵表導致的復制延遲問題,相關文章 #slave_rows_search_algorithms = TABLE_SCAN,INDEX_SCAN,HASH_SCAN #slave_net_timeout = 300 relay_log_recovery = 1 #sync_relay_log = 0 #sync_relay_log_info = 0 #sync_master_info = 0 # ssl-ca=/etc/mysql/cacert.pem # ssl-cert=/etc/mysql/server-cert.pem # ssl-key=/etc/mysql/server-key.pem [mysqldump] quick quote-names max_allowed_packet = 16M [mysql] #no-auto-rehash # faster start of mysql but no tab completition [isamchk] key_buffer = 16M # # * IMPORTANT: Additional settings that can override those from this file! # The files must end with '.cnf', otherwise they'll be ignored. #
!includedir /etc/mysql/conf.d/

該文章后續會不斷更新,慢慢完善。之前也介紹了MySQL5.5的配置文件,現在按照前2篇文章1文章2的信息,整理出該博文。對MySQL5.6的my.cnf 進行了配置(Percona MySQL),因為根據服務器硬件資源來調整的,所以一些內存、io刷寫的大小比例可以根據自己的條件來設置。

相關文章:

http://mysqllover.com/?p=575

http://dev.mysql.com/doc/refman/5.6/en/innodb-parameters.html

https://www.percona.com/doc/percona-server/5.6/ps-versions-comparison.html

https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM