Mysql database is thoroughly optimized under high Linux Load _ MySQL

Source: Internet
Author: User
At the same time, the online access volume continues to increase. for servers with 1 GB of memory, the server even crashes every day or gets stuck from time to time. This problem has plagued me for using MySQL for more than half a month. scalable algorithms, therefore, you can usually run with a small amount of memory or store MySQL more for better performance. MySQL optimization

At the same time, the online access volume continues to increase. for servers with 1 GB of memory, the server even crashes every day or gets stuck from time to time. This problem has plagued me for using MySQL for more than half a month. scalable algorithms, therefore, you can usually run with a small amount of memory or store MySQL more for better performance.

After installing mysql, the preparation file should be in the/usr/local/mysql/share/mysql directory, the preparation file has a few, there are my-huge.cnf my-medium.cnf my-large.cnf my-small.cnf, websites with different traffic and server environments with different configurations must have different configuration 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, that is, key_buffer_size, query_cache_size, and table_cache.

Key_buffer_size only applies to the MyISAM table,

Key_buffer_size specifies the size of the index buffer, which determines the index processing speed, especially the index reading 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 – 128M key_read_requests – 650759289 key_reads - 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
  

The value of Qcache_lowmem_prunes is very large, which indicates that the buffer is insufficient frequently. The value of Qcache_hits is very large, which indicates that the query buffer 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_blocks. if this 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.