{"id":6,"date":"2008-10-17T15:03:33","date_gmt":"2008-10-17T13:03:33","guid":{"rendered":"http:\/\/code.openark.org\/blog\/?p=6"},"modified":"2009-11-23T12:23:11","modified_gmt":"2009-11-23T10:23:11","slug":"mysql-parameters-configuration-sample-file","status":"publish","type":"post","link":"https:\/\/code.openark.org\/blog\/mysql\/mysql-parameters-configuration-sample-file","title":{"rendered":"MySQL parameters &#038; configuration sample file"},"content":{"rendered":"<p>The following is a sample my.cnf configuration file. It includes some common and uncommon parameters, along with occasional comments.<\/p>\n<p>You can use this file, and tune as appropriate for your machine, operating system, and application needs.<\/p>\n<p>In particular, note the high values set for the InnoDB related parameters, below, and change them to match your system and application&#8217;s requirements. You have been warned.<!--more--><\/p>\n<blockquote><p>[client]<br \/>\n<strong> #password       = [your_password]<br \/>\nport            = 3306<\/strong><br \/>\n# The following location is not the default location for many<br \/>\n# pre-packaged utilities. For example, mytop or mysqlreport<br \/>\n# (or any Perl or Python based client, for that matter), will<br \/>\n# NOT look in the \/tmp path for the mysql.sock file.<br \/>\n# The value is set to common location by your RPM or DEB<br \/>\n# package on GNU\/Linux, yet defaults to the following in the<br \/>\n# .tgz mysql-server downlaod files.<br \/>\n<strong> socket          = \/tmp\/mysql.sock<\/strong><\/p>\n<p><strong>default-character-set=utf8<\/strong><\/p>\n<p><strong>[mysqld]<\/strong><\/p>\n<p># For a new installation, best to use a strict sql_mode:<\/p>\n<p><strong>sql_mode=TRADITIONAL<br \/>\ndatadir= [path to mysql data]<br \/>\n<\/strong># I prefer working case-sensitive. However, some 3rd party tools<br \/>\n# demand case insensitivity. If you&#8217;re working with such a tool,<br \/>\n# uncomment the following line.<br \/>\n<strong>#lower_case_table_names=1<\/strong><\/p>\n<p># 5-10 minutes timeout is usually more than required for idle<br \/>\n# connections. If a connection can be idle for so long, then<br \/>\n# creating a new connection is usually very cheap. This applies<br \/>\n# for many common web based applications. However, depending<br \/>\n# on your application, you may wish to set this parameter to a<br \/>\n# higher value.<br \/>\n<strong> wait_timeout=300<\/strong><\/p>\n<p># The following is unfortunately still used on many instances. If<br \/>\n# you need backwards compatability, you may need to uncomment<br \/>\n# the following line.<br \/>\n<strong> #old_passwords=1<\/strong><\/p>\n<p># generic configuration options<br \/>\n<strong> port            = 3306<\/strong><br \/>\n# Make sure this is the same location as in the [client] section<br \/>\n<strong> socket          = \/tmp\/mysql.sock<\/strong><\/p>\n<p><strong>back_log = 50<br \/>\nmax_connect_errors = 10<\/strong><\/p>\n<p># Resources:<br \/>\n# The following values are liberal. You may reduce them<br \/>\n# according to your needs.<br \/>\n# NOTE: verify that your OS&#8217;s open files limit is at least as<br \/>\n# specified here.<br \/>\n# I usually set &#8216;ulimit -n&#8217; to allow for 8192 files to mysql.<br \/>\n<strong>open_files_limit = 8000<br \/>\n<\/strong># The following is usually cheap, so go ahead and set a high value.<br \/>\n<strong>table_cache = 2048<br \/>\n<\/strong># Connections take memory, so don;t be too liberal here. A common,<br \/>\n# well tuned application, using proper connection pools, shouldn&#8217;t<br \/>\n# require more than 1000 concurrent connections.<br \/>\n<strong>max_connections = 500<\/strong><\/p>\n<p># Memory:<br \/>\n# When required, the following parameters will be used to allocate<br \/>\n# more memory. The value specified is always the amount of memory<br \/>\n# allocated, regardless of the real need.<br \/>\n<strong>binlog_cache_size = 1M<br \/>\nmax_heap_table_size = 64M<br \/>\nsort_buffer_size = 8M<br \/>\njoin_buffer_size = 8M<br \/>\n<\/strong># The following value sets an upper limit only: MySQL will only<br \/>\n# allocate as much as required. Setting this parameters to a high<br \/>\n# value may be required if you&#8217;re handling very large statement,<br \/>\n# such as queries reading\/writing BLOBs.<br \/>\n<strong>max_allowed_packet = 16M<\/strong><\/p>\n<p># Even on a very busy server, a thread cache of 32 threads is<br \/>\n# usually enough to make for good thread recycling. I rarely go<br \/>\n# above this number.<br \/>\n<strong>thread_cache_size = 32<br \/>\nthread_concurrency = 8<\/strong><\/p>\n<p># Query cache:<br \/>\n# Make sure you really need the query cache. I&#8217;ve seen many<br \/>\n# applications where the query cache almost utterly unused<br \/>\n# (due to frequent invalidation). Check for your hit:insert ratio.<br \/>\n# A query cache type of value &#8220;2&#8221; (DEMAND) is a more programmatic<br \/>\n# oriented setting, where most queries are not cached, but a few,<br \/>\n# recognized to benefit from the query cache, are executed with<br \/>\n# the SQL_CACHE flag.<br \/>\n<strong>query_cache_type = 1<br \/>\nquery_cache_size = 32M<br \/>\nquery_cache_limit = 2M<\/strong><\/p>\n<p><strong>ft_min_word_len = 4<br \/>\n<\/strong># I usually go with InnoDB, which is ACID compliant and crash-safe.<br \/>\n<strong>default_table_type = InnoDB<\/strong><\/p>\n<p><strong>thread_stack = 192K<\/strong><\/p>\n<p><strong>transaction_isolation = REPEATABLE-READ<br \/>\ntmp_table_size = 64M<\/strong><\/p>\n<p># Logs<br \/>\n# Having log-bin enabled allows for replication and for point in time<br \/>\n# recovery. It&#8217;s a good idea to always have binary logs at hand.<br \/>\n# binary logs can also be reviewed to see what kind of modifications<br \/>\n# are made on your database (the general query log also logs<br \/>\n# SELECTs and other queries, which do not appear in the binary log)<br \/>\n# I usually name the logs after my host name. When dealing with<br \/>\n# replication, having master and slave logs named after the machines<br \/>\n# on which they are running makes for clearer distinction between<br \/>\n# them.<br \/>\n<strong>log-bin=mymachine-bin<br \/>\nrelay-log = mymachine-relay-bin<br \/>\nrelay-log-index = mymachine-relay-bin.index<br \/>\n<\/strong># Since a slave can suddenly be promoted to Master&#8217;s role, I always<br \/>\n# take care that it also has the binary logs prepared.<br \/>\n<strong>log_slave_updates<br \/>\nlog-error=mymachine-mysql-error.log<br \/>\nlog_slow_queries<br \/>\nlong_query_time = 2<br \/>\nlog-queries-not-using-indexes<br \/>\n<\/strong># Automatically remove binary logs. Make sure this number is not too<br \/>\n# high and not too low for you, depending on your backups frequency<br \/>\n# and maximum slave lag.<br \/>\n<strong>expire_logs_days=7<\/strong><\/p>\n<p># Replication related settings:<br \/>\n# Unique server identification number between 1 and 2^32-1.<br \/>\n<strong>server-id = [a unique number]<br \/>\n<\/strong># Setting the report_host allows for SHOW SLAVE HOSTS on the master<br \/>\n# to see which slaves are connected.<br \/>\n<strong>report_host=[machine&#8217;s ip]<br \/>\n<\/strong># Limit the total size of the relay logs: set this value to a high enough<br \/>\n# value. When the slave can&#8217;t keep up with the master, the relay logs<br \/>\n# fill up. If no limit is set, all disk space can be consumed.<br \/>\n# If a value too low is set, the master&#8217;s binary logs cannot (shouldn&#8217;t)<br \/>\n# be purged, and so the master gets to have a disk space problem. So<br \/>\n# provide a high enough value, and monitor your disk space!<br \/>\n<strong>relay_log_space_limit=10G<\/strong><\/p>\n<p># MyISAM:<br \/>\n<strong>key_buffer_size = 32M<br \/>\nread_buffer_size = 2M<br \/>\nread_rnd_buffer_size = 16M<br \/>\nbulk_insert_buffer_size = 64M<br \/>\nmyisam_sort_buffer_size = 128M<br \/>\nmyisam_max_sort_file_size = 10G<br \/>\nmyisam_max_extra_sort_file_size = 10G<br \/>\nmyisam_repair_threads = 1<br \/>\nmyisam_recover = force,backup<\/strong><\/p>\n<p><strong>concurrent_insert=2<br \/>\n<\/strong><\/p>\n<p># INNODB:<\/p>\n<p><strong>innodb_file_per_table<br \/>\n<\/strong># Your machine&#8217;s memory capacity dictates many of the following<br \/>\n# values. ***Do NOT take these values as they are. Change them***<br \/>\n<strong>innodb_buffer_pool_size = 10G<br \/>\ninnodb_additional_mem_pool_size = 16M<br \/>\ninnodb_data_file_path = ibdata1:50M:autoextend<br \/>\ninnodb_file_io_threads = 4<br \/>\n<\/strong># Keep the following one commented, unless you need to recover<br \/>\n# from disaster.<br \/>\n<strong>#innodb_force_recovery=4<br \/>\ninnodb_thread_concurrency = 8<br \/>\n<\/strong># Set &#8220;1&#8221; for full ACID compliance. Set &#8220;2&#8221; for IO performance gain<br \/>\n# (will only flush transaction log to disk once per second, instead<br \/>\n# of at each commit). If you have battery backed disk cache ,set<br \/>\n# to &#8220;1&#8221; and enjoy both worlds.<br \/>\n<strong>innodb_flush_log_at_trx_commit = 1<br \/>\n<\/strong># Keep the following one commented, unless you really have an<br \/>\n# emergency. Fast shutdown makes for slower start up time.<br \/>\n<strong>#innodb_fast_shutdown<br \/>\ninnodb_log_buffer_size = 8M<br \/>\n<\/strong># The default here is 5M, which is really too low for our modern<br \/>\n# machines.<br \/>\n<strong>innodb_log_file_size = 128M<br \/>\ninnodb_log_files_in_group = 2<br \/>\ninnodb_max_dirty_pages_pct = 90<br \/>\n<\/strong># Consult The manual. The desired values for the following<br \/>\n# parameter change according to your OS type, OS version and<br \/>\n# hardware types. Benchmark after changing it!<br \/>\n<strong>#innodb_flush_method=O_DIRECT<br \/>\ninnodb_lock_wait_timeout = 120<\/strong><\/p>\n<p><strong>[mysqldump]<br \/>\nquick<br \/>\nmax_allowed_packet = 64M<\/strong><\/p>\n<p><strong>default-character-set=utf8<\/strong><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>The following is a sample my.cnf configuration file. It includes some common and uncommon parameters, along with occasional comments. You can use this file, and tune as appropriate for your machine, operating system, and application needs. In particular, note the high values set for the InnoDB related parameters, below, and change them to match your [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[5],"tags":[11,10],"class_list":["post-6","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-configuration","tag-installation"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2bZZp-6","_links":{"self":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/6","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/comments?post=6"}],"version-history":[{"count":18,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/6\/revisions"}],"predecessor-version":[{"id":19,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/6\/revisions\/19"}],"wp:attachment":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/media?parent=6"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/categories?post=6"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/tags?post=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}