├── README.md ├── disable-transparent-hugepages └── my.cnf /README.md: -------------------------------------------------------------------------------- 1 | # MySQL Optimal Configuration File 2 | 3 | This configration file opts for MySQL 5.6 and 5.7. 4 | If you have any problem, dont hesitate to concact me. 5 | Let us make an optimal MySQL configuration file template for product enviroment. 6 | 7 | I assume the MySQL Server as followings. You should tune the variables according to your server. 8 | 9 | * 32 CPU core 10 | * 256G Memory 11 | * SSD storage with 20000 IOPS in 16K page size 12 | 13 | -------------------------------------------------------------------------------- /disable-transparent-hugepages: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: disable-transparent-hugepages 4 | # Required-Start: $local_fs 5 | # Required-Stop: 6 | # X-Start-Before: mongod mongodb-mms-automation-agent 7 | # Default-Start: 2 3 4 5 8 | # Default-Stop: 0 1 6 9 | # Short-Description: Disable Linux transparent huge pages 10 | # Description: Disable Linux transparent huge pages, to improve 11 | # database performance. 12 | ### END INIT INFO 13 | 14 | case $1 in 15 | start) 16 | if [ -d /sys/kernel/mm/transparent_hugepage ]; then 17 | thp_path=/sys/kernel/mm/transparent_hugepage 18 | elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then 19 | thp_path=/sys/kernel/mm/redhat_transparent_hugepage 20 | else 21 | return 0 22 | fi 23 | 24 | echo 'never' > ${thp_path}/enabled 25 | echo 'never' > ${thp_path}/defrag 26 | 27 | unset thp_path 28 | ;; 29 | esac 30 | -------------------------------------------------------------------------------- /my.cnf: -------------------------------------------------------------------------------- 1 | # author: jiangchengyao@gmail.com 2 | 3 | [client] 4 | user = root 5 | password = 1111aaA_ 6 | 7 | [mysql] 8 | prompt = [\\u@\\p][\\d]>\\_ 9 | no-auto-rehash 10 | 11 | [mysqld_safe] 12 | malloc-lib=tcmalloc 13 | 14 | [mysqldump] 15 | single-transaction 16 | 17 | [mysqld] 18 | # basic settings # 19 | user = mysql 20 | sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER" 21 | autocommit = 1 22 | server-id = 8888 23 | character_set_server=utf8mb4 24 | datadir=/mysql_data/data 25 | transaction_isolation = READ-COMMITTED 26 | explicit_defaults_for_timestamp = 1 27 | max_allowed_packet = 64M 28 | event_scheduler = 1 29 | 30 | # connection # 31 | interactive_timeout = 1800 32 | wait_timeout = 1800 33 | lock_wait_timeout = 1800 34 | skip_name_resolve = 1 35 | max_connections = 1024 36 | max_user_connections = 256 37 | max_connect_errors = 1000000 38 | 39 | # table cache performance settings 40 | table_open_cache = 4096 41 | table_definition_cache = 4096 42 | table_open_cache_instances = 64 43 | 44 | # session memory settings # 45 | read_buffer_size = 16M 46 | read_rnd_buffer_size = 32M 47 | sort_buffer_size = 32M 48 | tmp_table_size = 64M 49 | join_buffer_size = 128M 50 | thread_cache_size = 64 51 | 52 | # log settings # 53 | log_error = error.log 54 | log_bin = binlog 55 | log_error_verbosity = 2 56 | general_log_file = general.log 57 | slow_query_log = 1 58 | slow_query_log_file = slow.log 59 | log_queries_not_using_indexes = 1 60 | log_slow_admin_statements = 1 61 | log_slow_slave_statements = 1 62 | log_throttle_queries_not_using_indexes = 10 63 | expire_logs_days = 90 64 | long_query_time = 2 65 | min_examined_row_limit = 100 66 | log-bin-trust-function-creators = 1 67 | log-slave-updates = 1 68 | 69 | # innodb settings # 70 | innodb_page_size = 16384 71 | innodb_buffer_pool_size = 160G 72 | innodb_buffer_pool_instances = 16 73 | innodb_buffer_pool_load_at_startup = 1 74 | innodb_buffer_pool_dump_at_shutdown = 1 75 | innodb_lru_scan_depth = 4096 76 | innodb_lock_wait_timeout = 5 77 | innodb_io_capacity = 10000 78 | innodb_io_capacity_max = 20000 79 | innodb_flush_method = O_DIRECT 80 | innodb_undo_logs = 128 81 | innodb_undo_tablespaces = 3 82 | innodb_flush_neighbors = 0 83 | innodb_log_file_size = 16G 84 | innodb_log_files_in_group = 2 85 | innodb_log_buffer_size = 64M 86 | innodb_purge_threads = 4 87 | innodb_large_prefix = 1 88 | innodb_thread_concurrency = 32 89 | innodb_print_all_deadlocks = 1 90 | innodb_strict_mode = 1 91 | innodb_sort_buffer_size = 64M 92 | innodb_write_io_threads = 16 93 | innodb_read_io_threads = 16 94 | innodb_file_per_table = 1 95 | innodb_stats_persistent_sample_pages = 64 96 | innodb_autoinc_lock_mode = 2 97 | innodb_online_alter_log_max_size=1G 98 | innodb_open_files=4096 99 | 100 | # replication settings # 101 | master_info_repository = TABLE 102 | relay_log_info_repository = TABLE 103 | sync_binlog = 1 104 | gtid_mode = on 105 | enforce_gtid_consistency = 1 106 | log_slave_updates 107 | binlog_format = ROW 108 | binlog_rows_query_log_events = 1 109 | relay_log = relay.log 110 | relay_log_recovery = 1 111 | slave_skip_errors = ddl_exist_errors 112 | slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN' 113 | 114 | # semi sync replication settings # 115 | plugin-load = "group_replication.so;validate_password.so;semisync_master.so;semisync_slave.so" 116 | loose_rpl_semi_sync_master_enabled = 1 117 | loose_rpl_semi_sync_master_timeout = 3000 118 | loose_rpl_semi_sync_slave_enabled = 1 119 | 120 | # password plugin # 121 | validate_password_policy = STRONG 122 | validate-password = FORCE_PLUS_PERMANENT 123 | 124 | # perforamnce_schema settings 125 | performance-schema-instrument='memory/%=COUNTED' 126 | performance_schema_digests_size = 40000 127 | performance_schema_max_table_handles = 40000 128 | performance_schema_max_table_instances = 40000 129 | performance_schema_max_sql_text_length = 4096 130 | performance_schema_max_digest_length = 4096 131 | 132 | [mysqld-5.6] 133 | # metalock performance settings 134 | metadata_locks_hash_instances = 64 135 | 136 | [mysqld-5.7] 137 | # new innodb settings # 138 | loose_innodb_numa_interleave = 1 139 | innodb_buffer_pool_dump_pct = 40 140 | innodb_page_cleaners = 16 141 | innodb_undo_log_truncate = 1 142 | innodb_max_undo_log_size = 2G 143 | innodb_purge_rseg_truncate_frequency = 128 144 | 145 | # new replication settings # 146 | slave-parallel-type = LOGICAL_CLOCK 147 | slave-parallel-workers = 16 148 | slave_preserve_commit_order = 1 149 | slave_transaction_retries = 128 150 | # other change settings # 151 | binlog_gtid_simple_recovery = 1 152 | log_timestamps = system 153 | show_compatibility_56 = on 154 | 155 | # group replication settings 156 | plugin-load = "group_replication.so;validate_password.so;semisync_master.so;semisync_slave.so" 157 | transaction-write-set-extraction = XXHASH64 158 | # report_host = 127.0.0.1 # optional for group replication 159 | # binlog_checksum = NONE # only for group replication 160 | loose_group_replication = FORCE_PLUS_PERMANENT 161 | loose_group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" 162 | loose_group_replication_compression_threshold = 100 163 | loose_group_replication_flow_control_mode = 0 164 | loose_group_replication_single_primary_mode = 0 165 | loose_group_replication_enforce_update_everywhere_checks = 1 166 | loose_group_replication_transaction_size_limit = 10485760 167 | loose_group_replication_unreachable_majority_timeout = 120 168 | loose_group_replication_start_on_boot = 0 169 | --------------------------------------------------------------------------------