Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2020
1,266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.45 KB | None | 0 0
  1. # Optimized my.cnf configuration for MySQL/MariaSQL
  2. #
  3. # by Fotis Evangelou, developer of Engintron (engintron.com)
  4. #
  5. # ~ Updated January 2020 ~
  6. #
  7. #
  8. # The settings provided below are a starting point for a 2GB - 4GB RAM server with 2-4 CPU cores.
  9. # If you have different resources available you should adjust accordingly to save CPU, RAM & disk I/O usage.
  10. #
  11. # The settings marked with a specific comment or the word "UPD" (after the value)
  12. # should be adjusted for your system by using database diagnostics tools like:
  13. #
  14. # https://github.com/major/MySQLTuner-perl
  15. # or
  16. # https://github.com/RootService/tuning-primer (supports MySQL up to v5.7)
  17. #
  18. # Run either of these scripts before optimizing your database, at least 1 hr after the optimization & finally
  19. # at least once a day for 3 days (without restarting the database) to see how your server performs and if you need
  20. # to re-adjust anything. The more MySQL/MariaDB runs without restarting, the more usage data it gathers, so these
  21. # diagnostics scripts will report in mode detail how MySQL/MariaDB performs.
  22. #
  23. #
  24. # IMPORTANT NOTE: If there is NO comment after a setting value, then 99,9% of the times you won't need to adjust it.
  25. #
  26. #
  27. # --- THINGS TO DO AFTER YOU UPDATE MY.CNF - TROUBLESHOOTING ---
  28. #
  29. # If any terminal commands are mentioned, make sure you execute them as "root" user.
  30. #
  31. # If MySQL or MariaDB cannot start (or restart), then perform the following actions.
  32. #
  33. # 1. If the server had the stock database configuration and you added or updated any
  34. # "innodb_log_*" settings (as suggested below), then execute these commands ONLY
  35. # the first time you apply this configuration:
  36. #
  37. # $ rm -rvf /var/lib/mysql/ib_logfile*
  38. # $ chown -R mysql:mysql /var/lib/mysql
  39. # $ service mysql restart
  40. #
  41. # or use the shorthand command:
  42. # $ rm -rvf /var/lib/mysql/ib_logfile*; chown -R mysql:mysql /var/lib/mysql; service mysql restart
  43. #
  44. # 2. If the setting "bind-address" is not commented out, then make sure the file /etc/hosts is
  45. # properly configured. A good example of a "clean" /etc/hosts file is something like this:
  46. #
  47. # 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  48. # ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  49. # 1.2.3.4 hostname.domain.tld hostname # <-- Replace accordingly!
  50. #
  51. # Finally restart the database service:
  52. #
  53. # $ service mysql restart
  54. #
  55. # 3. If the database service cannot restart even after the first 2 steps, make sure the database data folder
  56. # (common for either MySQL or MariaDB) "/var/lib/mysql" is owned by the "mysql" user AND group.
  57. # Additionally, the folder itself can have 0751 or 0755 file permissions. To fix it, simply do this:
  58. # $ chown -R mysql:mysql /var/lib/mysql
  59. # $ chmod 0755 /var/lib/mysql
  60. #
  61. # Finally restart the database service:
  62. #
  63. # $ service mysql restart
  64. #
  65. #
  66. # ~ FIN ~
  67.  
  68.  
  69. [mysql]
  70. port = 3306
  71. socket = /var/run/mysqld/mysqld.sock
  72.  
  73. [mysqld]
  74. # Required Settings
  75. basedir = /usr
  76. bind_address = 127.0.0.1 # Change to 0.0.0.0 to allow remote connections
  77. datadir = /var/lib/mysql
  78. max_allowed_packet = 256M
  79. max_connect_errors = 1000000
  80. pid_file = /var/run/mysqld/mysqld.pid
  81. port = 3306
  82. skip_external_locking
  83. skip_name_resolve
  84. socket = /var/run/mysqld/mysqld.sock
  85.  
  86.  
  87. # Enable for b/c with databases created in older MySQL/MariaDB versions (e.g. when using null dates)
  88. #sql_mode = ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES
  89.  
  90. tmpdir = /tmp
  91. user = mysql
  92.  
  93. # InnoDB Settings
  94. default_storage_engine = InnoDB
  95. innodb_buffer_pool_instances = 24 # Use 1 instance per 1GB of InnoDB pool size
  96. innodb_buffer_pool_size = 24G # Use up to 70-80% of RAM
  97. innodb_file_per_table = 4
  98. innodb_flush_log_at_trx_commit = 0
  99. innodb_flush_method = O_DIRECT
  100. innodb_log_buffer_size = 16M
  101. innodb_log_file_size = 512M
  102. innodb_stats_on_metadata = 0
  103.  
  104. innodb_temp_data_file_path = ibtmp1:64M:autoextend:max:20G # Control the maximum size for the ibtmp1 file
  105. innodb_thread_concurrency = 6 # Optional: Set to the number of CPUs on your system (minus 1 or 2) to better
  106. # contain CPU usage. E.g. if your system has 8 CPUs, try 6 or 7 and check
  107. # the overall load produced by MySQL/MariaDB.
  108. innodb_read_io_threads = 64
  109. innodb_write_io_threads = 64
  110.  
  111. # MyISAM Settings
  112. query_cache_limit = 4M # UPD - Option supported by MariaDB & up to MySQL 5.7, remove this line on MySQL 8.x
  113. query_cache_size = 64M # UPD - Option supported by MariaDB & up to MySQL 5.7, remove this line on MySQL 8.x
  114. query_cache_type = 1 # Option supported by MariaDB & up to MySQL 5.7, remove this line on MySQL 8.x
  115.  
  116. key_buffer_size = 32M # UPD
  117.  
  118. low_priority_updates = 1
  119. concurrent_insert = 2
  120.  
  121. # Connection Settings
  122. max_connections = 100 # UPD
  123.  
  124. back_log = 512
  125. thread_cache_size = 100
  126. thread_stack = 192K
  127.  
  128. interactive_timeout = 180
  129. wait_timeout = 180
  130.  
  131. # For MySQL 5.7+ only (disabled by default)
  132. #max_execution_time = 30000 # Set a timeout limit for SELECT statements (value in milliseconds).
  133. # This option may be useful to address aggressive crawling on large sites,
  134. # but it can also cause issues (e.g. with backups). So use with extreme caution and test!
  135. # More info at: https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_max_execution_time
  136.  
  137. # For MariaDB 10.1.1+ only (disabled by default)
  138. #max_statement_time = 30 # The equivalent of "max_execution_time" in MySQL 5.7+ (set above)
  139. # The variable is of type double, thus you can use subsecond timeout.
  140. # For example you can use value 0.01 for 10 milliseconds timeout.
  141. # More info at: https://mariadb.com/kb/en/aborting-statements/
  142.  
  143. # Buffer Settings
  144. join_buffer_size = 4M # UPD
  145. read_buffer_size = 3M # UPD
  146. read_rnd_buffer_size = 4M # UPD
  147. sort_buffer_size = 4M # UPD
  148.  
  149. # Table Settings
  150. # In systemd managed systems like Ubuntu 16.04+ or CentOS 7+, you need to perform an extra action for table_open_cache & open_files_limit
  151. # to be overriden (also see comment next to open_files_limit).
  152. # E.g. for MySQL 5.7, please check: https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html
  153. # and for MariaDB check: https://mariadb.com/kb/en/library/systemd/
  154. table_definition_cache = 40000 # UPD
  155. table_open_cache = 40000 # UPD
  156. open_files_limit = 60000 # UPD - This can be 2x to 3x the table_open_cache value or match the system's
  157. # open files limit usually set in /etc/sysctl.conf or /etc/security/limits.conf
  158. # In systemd managed systems this limit must also be set in:
  159. # /etc/systemd/system/mysqld.service.d/override.conf (for MySQL 5.7+) and
  160. # /etc/systemd/system/mariadb.service.d/override.conf (for MariaDB)
  161.  
  162. max_heap_table_size = 128M
  163. tmp_table_size = 128M
  164.  
  165. # Search Settings
  166. ft_min_word_len = 3 # Minimum length of words to be indexed for search results
  167.  
  168. # Logging
  169. log_error = /var/lib/mysql.log
  170. log_queries_not_using_indexes = 1
  171. long_query_time = 5
  172. slow_query_log = 0 # Disabled for production
  173. slow_query_log_file = /var/lib/mysql-slow.log
  174.  
  175. [mysqldump]
  176. # Variable reference
  177. # For MySQL 5.7: https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html
  178. # For MariaDB: https://mariadb.com/kb/en/library/mysqldump/
  179. quick
  180. quote_names
  181. max_allowed_packet = 64M
  182.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement