After installing mysql, the preparation file should be in the/usr/local/mysql/share/mysql directory. There are several preparation files, including my-huge. cnf my-medium.cnf my-large.cnf my-small.cnf, different traffic of the site and different preparation of the server environment, of course, need to have different preparation files.
Under normal circumstances, the preparation of the my-medium.cnf file can meet most of our needs; general we will copy the configuration file to/etc/my. cnf only needs to modify this configuration file. You can use mysqladmin variables extended-status-u root-p to see the current parameters. Three configuration parameters are the most important, namely:
Key_buffer_size Query_cache_size Table_cache |
Key_buffer_size only applies to the MyISAM table.
Key_buffer_sizeSpecify the size of the index buffer, which determines the index processing speed, especially the index read speed. Generally, we set the value to 16 M. In fact, the number of sites that are slightly larger is far from enough. By checking the status values Key_read_requests and Key_reads, we can check whether the key_buffer_size setting is reasonable. The ratio of key_reads/key_read_requests should be as low as possible, at least and (the above STATUS values can be obtained using show status like 'key _ read % ). Or if you have installed phpmyadmin, you can see it through the server running status. I recommend you use phpmyadmin to manage mysql. The following status values are all my instance analysis obtained through phpmyadmin:
This server has been running for 20 days
Key _buffer_size-128 M Key_read_requests-650759289 Key_read-79112 |
Ratio close to 1: 8000 healthy
Another way to estimate the key_buffer_size is to add up the size of the index space of each table in your website database. Take this server as an example: the number of large table indexes is about 125 MB, which will increase as the table grows.
MySQL provides a query buffer mechanism starting from 4.0.1. Using the Query Buffer, MySQL stores the SELECT statement and query result in the buffer. In the future, the same SELECT statement (case sensitive) will be read directly from the buffer. According to the MySQL user manual, query buffering can achieve a maximum efficiency of 238%.
You can check whether query_cache_size is set properly by adjusting the following parameters.
Qcache inserts Qcache hits Qcache lowmem prunes Qcache free blocks Qcache total blocks |
Qcache_lowmem_prunesIf the value of Qcache_hits is very large, it indicates that the cache is frequently used. In this case, the value of Qcache_hits is not large, this indicates that your query repetition rate is very low. In this case, using the Query Buffer will affect the efficiency, so you can consider not to use the query buffer. In addition, adding SQL _NO_CACHE to the SELECT statement explicitly indicates that no Query Buffer is used.
Qcache_free_blocksIf the value is very large, it indicates that many fragments in the buffer zone query_cache_type specify whether to use the query buffer.
My settings:
Query_cache_size = 32 M Query_cache_type = 1 |
Obtain the following status values:
Qcache queries in cache 12737 indicates the number of items currently cached Qcache inserts 20649006 Qcache hits 79060095 seems that the repeat query rate is quite high Qcache lowmem prunes 617913 has so many times that the cache is too low Qcache not cached 189896 Qcache free memory 18573912 Qcache free blocks 5328 seems to be a little big. Qcache total blocks 30953 |
If the memory allows 32 MB, you should add some more
Table_cache specifies the table cache size. When MySQL accesses a table, if there is space in the table buffer, the table is opened and put into it, so that the table content can be accessed more quickly. Check the status values Open_tables and Opened_tables of the peak time to determine whether to increase the value of table_cache. If you find that open_tables is equal to table_cache and opened_tables is growing, you need to increase the value of table_cache (the preceding STATUS values can be obtained using show status like 'open % tables ). Note that you cannot blindly set table_cache to a large value. If it is set too high, the file descriptor may be insufficient, resulting in unstable performance or connection failure.
For machines with 1 GB memory, the recommended value is 128-256.
Set by the authorTable_cache = 256
The following status is displayed:
Opening tables 256 Opened tables 9046 |
Although open_tables is already equal to table_cache, opened_tables has a very low value after 20 days of running compared to the server running time. Therefore, increasing the value of table_cache should be of little use. If the preceding value appears after six hours, you need to increase the value of table_cache.