my.cnf 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. [mysqld]
  2. # ===== 基础设置 =====
  3. datadir = /data/mysql/data/mysql
  4. socket = /data/mysql/data/mysql/mysql.sock
  5. port = 13306
  6. user = root
  7. # ===== 日志设置 =====
  8. log-error = /data/mysql/log/mysqld.log
  9. pid-file = /var/run/mysqld/mysqld.pid
  10. # 关闭慢查询日志以减少IO和内存开销
  11. slow_query_log = 0
  12. # ===== 连接和线程设置 =====
  13. # 连接池设置(4G内存优化)
  14. max_connections = 800
  15. max_connect_errors = 10000
  16. back_log = 500
  17. # 线程缓存(增加连接数后相应调整)
  18. thread_cache_size = 64
  19. # 连接超时设置
  20. connect_timeout = 10
  21. wait_timeout = 1800
  22. interactive_timeout = 1800
  23. # ===== 内存和缓存设置(小内存优化) =====
  24. # InnoDB缓冲池(4G内存下优化为70%)
  25. # 4G内存:800M缓冲池,4个实例
  26. innodb_buffer_pool_size = 800M
  27. innodb_buffer_pool_instances = 4
  28. # InnoDB日志设置(适当减小)
  29. innodb_log_file_size = 64M
  30. innodb_log_files_in_group = 2
  31. innodb_log_buffer_size = 8M
  32. # 其他InnoDB设置
  33. innodb_flush_log_at_trx_commit = 1
  34. innodb_flush_method = O_DIRECT
  35. innodb_file_per_table = 1
  36. innodb_open_files = 1024
  37. # 关闭查询缓存
  38. query_cache_type = 0
  39. query_cache_size = 0
  40. # 表缓存(增加连接数后相应调整)
  41. table_open_cache = 2048
  42. table_definition_cache = 1024
  43. # ===== 高并发优化(精简版) =====
  44. # InnoDB并发设置
  45. innodb_thread_concurrency = 0
  46. innodb_read_io_threads = 4
  47. innodb_write_io_threads = 4
  48. # 锁和事务设置
  49. innodb_lock_wait_timeout = 30
  50. transaction_isolation = READ-COMMITTED
  51. # 排序和临时表(4G内存下适当增加)
  52. sort_buffer_size = 256K
  53. read_buffer_size = 128K
  54. read_rnd_buffer_size = 256K
  55. join_buffer_size = 256K
  56. tmp_table_size = 32M
  57. max_heap_table_size = 32M
  58. # ===== 网络和包设置 =====
  59. max_allowed_packet = 16M
  60. # ===== 性能和安全 =====
  61. # 关闭性能模式以减少内存占用
  62. performance_schema = OFF
  63. # 安全限制(增加最大连接数)
  64. max_user_connections = 500
  65. skip_name_resolve = 1
  66. # ===== 其他优化 =====
  67. # 字符集
  68. character-set-server = utf8mb4
  69. collation-server = utf8mb4_unicode_ci
  70. # 默认存储引擎
  71. default_storage_engine = InnoDB
  72. # 禁止符号链接
  73. symbolic-links = 0
  74. [client]
  75. port = 13306
  76. socket = /data/mysql/data/mysql/mysql.sock
  77. default-character-set = utf8mb4
  78. [mysql]
  79. default-character-set = utf8mb4
  80. [mysqld_safe]
  81. log-error = /data/mysql/log/mysqld.log
  82. pid-file = /var/run/mysqld/mysqld.pid