Inside 君整理了一份最新基于 MySQL 5.6 和 5.7 的配置文件模板,基本上可以说覆盖 90% 的调优选项,用户只需根据自己的服务器配置稍作修改即可,如 InnoDB 缓冲池的大小、IO 能力(innodb_buffer_pool_size,innodb_io_capacity)。特别注意,这份配置文件不用修改,可以直接运行在 MySQL 5.6 和 5.7 的版本下,这里使用了小小的技巧,具体可看配置文件。如果配置参数存在问题,也可以及时反馈 Inside 君,我们一起成长。

    触发 Inside 君做这件事情的原因是大部分网络上的 MySQL 配置文件都非常非常古老,大多都是基于 MySQL 5.1 的版本,这导致了绝大部分 MySQL 并没有运行在最优的环境,从而导致一些错误的使用,亦或是灾难性事故的发生,比如数据丢失,主从数据不一致等。而这些问题早在 5.6 版本及以后的版本中得到了解决。

    最后,抛弃你那所谓的、陈旧的、错误的 MySQL 配置文件,面向一个崭新的高性能、高可靠、高可扩展 MySQL 时代,你要做的就是下载这份配置文件并用于你的生产环境。

    insidemysql_my.cnf:insidemysql_my.rar

    1. [client]
    2. user=david
    3. password=88888888
    4. [mysqld]
    5. ########basic settings########
    6. server-id = 11
    7. port = 3306
    8. user = mysql
    9. bind_address = 10.166.224.32
    10. autocommit = 0
    11. character_set_server=utf8mb4
    12. skip_name_resolve = 1
    13. max_connections = 800
    14. max_connect_errors = 1000
    15. datadir = /data/mysql_data
    16. transaction_isolation = READ-COMMITTED
    17. explicit_defaults_for_timestamp = 1
    18. join_buffer_size = 134217728
    19. tmp_table_size = 67108864
    20. tmpdir = /tmp
    21. max_allowed_packet = 16777216
    22. sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
    23. interactive_timeout = 1800
    24. wait_timeout = 1800
    25. read_buffer_size = 16777216
    26. read_rnd_buffer_size = 33554432
    27. sort_buffer_size = 33554432
    28. ########log settings########
    29. log_error = error.log
    30. slow_query_log = 1
    31. slow_query_log_file = slow.log
    32. log_queries_not_using_indexes = 1
    33. log_slow_admin_statements = 1
    34. log_slow_slave_statements = 1
    35. log_throttle_queries_not_using_indexes = 10
    36. expire_logs_days = 90
    37. long_query_time = 2
    38. min_examined_row_limit = 100
    39. ########replication settings########
    40. master_info_repository = TABLE
    41. relay_log_info_repository = TABLE
    42. log_bin = bin.log
    43. sync_binlog = 1
    44. gtid_mode = on
    45. enforce_gtid_consistency = 1
    46. log_slave_updates
    47. binlog_format = row
    48. relay_log = relay.log
    49. relay_log_recovery = 1
    50. binlog_gtid_simple_recovery = 1
    51. slave_skip_errors = ddl_exist_errors
    52. ########innodb settings########
    53. innodb_page_size = 8192
    54. innodb_buffer_pool_size = 6G
    55. innodb_buffer_pool_instances = 8
    56. innodb_buffer_pool_load_at_startup = 1
    57. innodb_buffer_pool_dump_at_shutdown = 1
    58. innodb_lru_scan_depth = 2000
    59. innodb_lock_wait_timeout = 5
    60. innodb_io_capacity = 4000
    61. innodb_io_capacity_max = 8000
    62. innodb_flush_method = O_DIRECT
    63. innodb_file_format = Barracuda
    64. innodb_file_format_max = Barracuda
    65. innodb_log_group_home_dir = /redolog/
    66. innodb_undo_directory = /undolog/
    67. innodb_undo_logs = 128
    68. innodb_undo_tablespaces = 3
    69. innodb_flush_neighbors = 1
    70. innodb_log_file_size = 4G
    71. innodb_log_buffer_size = 16777216
    72. innodb_purge_threads = 4
    73. innodb_large_prefix = 1
    74. innodb_thread_concurrency = 64
    75. innodb_print_all_deadlocks = 1
    76. innodb_strict_mode = 1
    77. innodb_sort_buffer_size = 67108864
    78. ########semi sync replication settings########
    79. plugin_dir=/usr/local/mysql/lib/plugin
    80. plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
    81. loose_rpl_semi_sync_master_enabled = 1
    82. loose_rpl_semi_sync_slave_enabled = 1
    83. loose_rpl_semi_sync_master_timeout = 5000
    84. [mysqld-5.7]
    85. innodb_buffer_pool_dump_pct = 40
    86. innodb_page_cleaners = 4
    87. innodb_undo_log_truncate = 1
    88. innodb_max_undo_log_size = 2G
    89. innodb_purge_rseg_truncate_frequency = 128
    90. binlog_gtid_simple_recovery=1
    91. log_timestamps=system
    92. transaction_write_set_extraction=MURMUR32
    93. show_compatibility_56=on

    作者:殷建卫 链接:https://www.yuque.com/yinjianwei/vyrvkf/tb8uaw 来源:殷建卫 - 架构笔记 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。