#This configration file opts for MySQL 8.0.20 #Let us make an optimal MySQL configuration file template for product enviroment. # #I assume the MySQL Server as followings. You should tune the variables according to your server. # #* 32 CPU core #* 256G Memory #* SSD storage with 20000 IOPS in 16K page size [client] ##client標籤設置mysql、mysqldump、mysqladmin的變量。 user = root password = 1111aaA_ [mysql] ##mysql標籤設置mysql客戶端的變量。 prompt = [\\u@\\p][\\d]>\\_ tee = "/tmp/tee.log" ##設置客戶端的查詢日誌 pager = "less -i -n -S" ##分頁顯示查詢出的數據,方便搜索查詢到的數據 no-auto-rehash ##關閉預讀取元數據 [mysqld_safe] [mysqldump] single-transaction [mysqld] # basic settings # innodb_temp_data_file_path ##研究一下這個參數設置成多少合適。 default_authentication_plugin=mysql_native_password sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER" ##server_id = 8888 ##datadir = /mysql_data/data transaction_isolation = READ-COMMITTED event_scheduler = OFF open_files_limit = 327675 ##設置MySQL運行過程當中能夠打開的文件數,避免出現「too many open files」報錯。建議設置值使用公式:10+max_connections+(table_open_cache*2)。 secure_file_priv = /tmp # connection # interactive_timeout = 600 ##交互式鏈接超時時間(mysql工具、mysqldump工具等) wait_timeout = 600 ##非交互式鏈接超時時間。指鏈接mysql的api程序,jdbc鏈接等。 lock_wait_timeout = 1800 ##DDL操做的鎖等待時間 skip_name_resolve = ON max_connections = 1024 max_user_connections = 256 max_connect_errors = 1000000 # table cache performance settings # table_open_cache = 4096 table_definition_cache = 4096 table_open_cache_instances = 64 # session memory settings # read_buffer_size = 16M read_rnd_buffer_size = 32M sort_buffer_size = 32M tmp_table_size = 64M join_buffer_size = 128M thread_cache_size = 64 # optimizer switch settings # optimizer_switch = 'index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=off,block_nested_loop=on,batched_key_access=off,materialization=on,semijoin=on,loosescan=on,firstmatch=on,duplicateweedout=on,subquery_materialization_cost_based=on,use_index_extensions=on,condition_fanout_filter=on,derived_merge=on,use_invisible_indexes=off,skip_scan=on,hash_join=on' ##優化器開關設置。 # log settings # log_timestamps = system ##general_log = ON ##general_log_file = /usr/local/mysql/data/MySQL01-general.log slow_query_log = ON long_query_time = 1 ##slow_query_log_file = /usr/local/mysql/data/MySQL01-slow.log log_queries_not_using_indexes = ON log_slow_admin_statements = ON ##log_slow_slave_statements = ON log_throttle_queries_not_using_indexes = 10 expire_logs_days = 90 min_examined_row_limit = 100 log_bin_trust_function_creators = ON # innodb settings # innodb_buffer_pool_size = 160G innodb_buffer_pool_instances = 16 innodb_page_cleaners = 16 ##設置page clean線程的個數。這個值推薦和innodb_buffer_poool_instances相等。該值大於innodb_buffer_poool_instances時,自動設置爲與innodb_buffer_poool_instances相同的值。 innodb_lru_scan_depth = 2048 ##控制LRU列表中可用頁的數量。默認值1024。寫密集型負載使IO飽和,或者使用機械盤時建議使用默認值。調整innodb_lru_scan_depth時,從一個較低的值開始,向上配置設置,目標是不多看到零空閒頁面。另外,在更改緩衝池實例的數量時,考慮調整innodb_lru_scan_depth,由於innodb_lru scan_depth*innodb_buffer_pool_instances定義了頁面清理線程每秒執行的工做量。推薦使用默認值。 innodb_fast_shutdown = 0 ##設置innodb關機模式。有效值0、一、2。0表示執行慢關機,即在關閉前完全清除和更改緩衝區合併,這種模式下開機是最快的;1表示關機時跳過上述操做,可是在開機時會執行上述操做,稱爲快關機;2表示刷新其日誌並冷關閉,不會丟失任何已提交的事務下,得到最快的關機,這種模式是開機最慢的。 innodb_max_dirty_pages_pct = 80 ##設置當緩衝池中髒頁達到百分之80時,強制進行checkpoint,將一部分髒頁刷新到磁盤上。默認值90。推薦值80。這個值不建議設置過小,設置過小會加劇IO的寫操做。 innodb_buffer_pool_dump_pct = 80 ##正常關機時將innodb_buffer_pool中百分之八十的數據保存到磁盤中 innodb_lock_wait_timeout = 5 ##innodb dml鎖的等待超時時間,單位秒。 innodb_rollback_on_timeout = ON ##等待超時的事務進行回滾。 innodb_io_capacity = 400 ##設置後臺線程每秒操做IO的次數。默認值200。理想狀況下儘量低,若是太大會從緩衝池中清除過多的數據,反而使緩衝池失去了「緩衝」的做用。對於SSD磁盤默認值200已經足夠。15000轉的機械磁盤建議設置爲200。15000轉如下的機械磁盤建議設置爲100。 innodb_io_capacity_max = 2000 ##設置在刷新落後時,後臺任務執行的最大IOPS數。默認值2000。最小值也是2000。這個值在使用SSD磁盤時也無需調大。 innodb_flush_method = O_DIRECT innodb_flush_neighbors = 0 ##對於SSD盤將這個值設置爲0。因爲該功能會使不怎麼髒的頁進行了寫入,然後該頁又會很快變成髒頁,而固態硬盤有超高的IOPS,所以要置爲0。可選值1表示刷新相同範圍內連續的髒頁,可選值2表示刷新相同範圍內的髒頁。 innodb_undo_tablespaces = 3 innodb_log_file_size = 1900MB ##這個值是百度公司統一的。 innodb_log_files_in_group = 2 innodb_log_buffer_size = 64MB innodb_checksum_algorithm = strict_crc32 ##設置innodb存儲引擎每次讀取頁時,使用checksum函數的哪一個算法。 innodb_thread_concurrency = 32 innodb_print_all_deadlocks = ON ##將死鎖信息打印到mysql錯誤日誌中 innodb_sort_buffer_size = 64M innodb_write_io_threads = 16 innodb_read_io_threads = 16 innodb_stats_persistent_sample_pages = 64 innodb_online_alter_log_max_size = 1G innodb_open_files = 4096 # replication settings # sync_binlog = 1 ##當有多個從庫,而且開啓了半同步複製這個值能夠設置成1000。百度公司在半同步複製時統一設置成1000。 ##gtid_mode = ON ##enforce_gtid_consistency = ON ##binlog_gtid_simple_recovery = ON log_slave_updates = OFF binlog_rows_query_log_events = ON relay_log_recovery = ON ##slave_skip_errors = ddl_exist_errors # replication settings for slave # ##slave_parallel_workers = 16 ##設置多線程SQL線程數量 ##slave_parallel_type = LOGICAL_CLOCK ##設置多線程複製的模式 ##slave_preserve_commit_order = ON ##slave_transaction_retries = 128 # semi sync replication settings # ##rpl_semi_sync_master_enabled = ON ##rpl_semi_sync_master_timeout = 1000 # semi sync replication settings for slave # ##rpl_semi_sync_slave_enabled = ON # perforamnce_schema settings performance_schema_digests_size = 40000 performance_schema_max_table_handles = 40000 performance_schema_max_table_instances = 40000 performance_schema_max_sql_text_length = 4096 performance_schema_max_digest_length = 4096 # group replication settings # ##plugin-load = "group_replication.so;validate_password.so;semisync_master.so;semisync_slave.so" ##transaction-write-set-extraction = XXHASH64 ##report_host = 127.0.0.1 # optional for group replication ##binlog_checksum = NONE # only for group replication ##loose_group_replication = FORCE_PLUS_PERMANENT ##loose_group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" ##loose_group_replication_compression_threshold = 100 ##loose_group_replication_flow_control_mode = 0 ##loose_group_replication_single_primary_mode = 0 ##loose_group_replication_enforce_update_everywhere_checks = 1 ##loose_group_replication_transaction_size_limit = 10485760 ##loose_group_replication_unreachable_majority_timeout = 120 ##loose_group_replication_start_on_boot = 0