⬆️ ⬇️

Setup and optimization of MySQL server

This article will describe the various MySQL settings, mainly those that affect performance. For convenience, all variables are divided into sections (basic settings, restrictions, settings streams, query caching, timings, buffers, InnoDB). First, we clarify the names of some variables that have changed in version 4 of MySQL, and the network continues to meet both old and new variants of names, which causes questions.



So, in version 4 a number of variables appeared ending _size . This applies to the thread_cache_size variable and variables from the Buffers section. And the variable read_buffer_size to version 4 was called record_buffer . Also, the variable skip_external_locking from the Basic Settings section prior to version 4 was called skip_locking .

Variables are divided into two main categories: variables with values ​​and variable flags. Variables with values ​​are written in the configuration file as variable = value , and variable flags are simply specified. You also probably noticed that in some cases the names of variables use " - ", and in some " _ ". Variables with a hyphen are the starting options of the server and cannot be changed while the server is running (using SET); Underlined variables are server options and can be changed on the fly. If we are talking about a “state variable” or it is recommended to monitor the value of a variable whose name is recorded as Variable_Name , then you should run the SHOW STATUS LIKE "Variable_Name" query to get the value of this variable, or look at the status tab in phpMyAdmin, where you will also see comments by the value of this variable.

And now we will be engaged in the description of variables and their possible values.



Basic settings





Restrictions





Streaming settings





Query caching





The query cache can be thought of as a hash array, the keys of which are queries, and the values ​​are the results of queries. In addition to the results, MySQL caches a list of tables, a selection of which is cached. If any of the tables, the sample from which is in the cache, are changed, then MySQL removes such samples from the cache. Also, MySQL does not cache queries whose results may change.

When you start MySQL allocates a block of memory size in query_cache_size . When the query is executed, as soon as the first result lines are received, the server starts caching them: it allocates a block of memory equal to query_cache_min_res_unit in the cache, writes the result of the selection to it. If not all of the sample fit into the block, the server allocates the next block, and so on. At the moment of writing, MySQL does not know about the size of the resulting sample, so if the sample size recorded in the cache is larger than query_cache_limit , then the recording stops and the space occupied is released, therefore, if you know in advance that the result will be large, you should execute it with the directive SQL_NO_CACHE .



Timings





Buffers



All buffers have a common feature - if, due to the large buffer size, the data goes to the paging file, then the buffer will do more harm than good. Therefore, always be guided by the amount of physical RAM available to you.



The values ​​in the configuration file are specified in bytes, respectively, kilobytes and megabytes must be converted to bytes.

')

InnoDB





It is also convenient to use phpMyAdmin to monitor server performance, the Status and Variables tabs are of interest. Additionally, phpMyAdmin gives tips on tuning certain variables depending on the server operation parameters.

In preparing the article, in addition to official documentation and own head, the following materials were used:



I will read with interest the comments, comments and additions.

Additional discussion of the article can be found here .

Source: https://habr.com/ru/post/108418/



All Articles