Practical Operation solution for optimizing MySQL database performance

Source: Internet
Author: User

The following articles mainly introduce the actual operation solution for optimizing MySQL database performance. We all know that the speed or slowness of MySQL database is mainly determined by the configuration optimization, if we use it on our own, for example, when there are a few people, even if the number of people is small, we cannot see any effect.

If the number of people is very large, we can see that the following ten important parameter configurations are introduced: max_connections, record_buffer, back_log, interactive_timeout, sort_buffer, table_cache, thread_cache_size, after the wait_timeout parameters are configured, the MySQL database performance will be greatly optimized. The second page provides a recommended configuration.

1. max_connections:

Number of customers allowed simultaneously. Increase the number of file descriptors required by MySQLd. This number should be added. Otherwise, you will often see the too connector connections error. The default value is 100. I will change it to 1024.

Ii. record_buffer:

Each thread that performs an ordered scan allocates a buffer of this size to each table it scans. If you perform many sequential scans, you may want to increase the value. The default value is 131072 (128 k). I changed it to 16773120 (16 m)

3. key_buffer_size:

The index block is buffered and shared by all threads. Key_buffer_size is the buffer size used for index blocks. You can increase the size of indexes that can be better processed (for all reads and multi-Rewrite) so that you can afford that much. If you make it too large, the system will begin to change pages and it will really slow down. The default value is 8388600 (8 m). My MySQL host has 2 GB of memory, so I changed it to 402649088 (400 mb ).

Iv. back_log:

The number of connections that MySQL can have. When the main MySQL thread receives a lot of connection requests in a very short period of time, this works, and then the main thread takes some time (although very short) to check the connection and start a new thread.

The back_log value indicates how many requests can be stored in the stack within a short time before MySQL temporarily stops answering new requests. Only if you want to have many connections in a short period of time, you need to increase it. In other words, this value is the size of the listener queue for the incoming TCP/IP connection. Your operating system has its own limit on the queue size. Trying to set back_log to be higher than your operating system limit will be invalid.

When you observe the process list of your host and find a large number of 264084 | unauthenticated user | xxx. xxx. xxx. xxx | null | connect | null | login | when a null process is to be connected, increase the value of back_log. The default value is 50. I will change it to 500.

5. interactive_timeout:

The number of seconds that the server waits for action on an interactive connection before closing it. An interactive customer is defined as a customer who uses the client_interactive option for MySQL_real_connect. The default value is 28800. I will change it to 7200.

6. sort_buffer:

Each thread that needs to be sorted allocates a buffer of this size. Add this value to accelerate the order by or group by operation. The default value is 2097144 (2 m). I changed it to 16777208 (16 m ).

VII. table_cache:

Number of tables opened for all threads. Increase this value to increase the number of file descriptors required by MySQLd. MySQL requires two file descriptors for each unique opened table. The default value is 64. I changed it to 512.

8. thread_cache_size:

The number of threads that can be reused. If yes, the new thread is obtained from the cache. If there is space when the connection is disconnected, the customer's thread is placed in the cache. If there are many new threads, this variable value can be used to improve performance. By comparing variables in connections and threads_created states, you can see the role of this variable. I set it to 80.

9. MySQL search

MySQL is used for search. It is case-insensitive and can be searched in Chinese. You only need to specify -- default-character-set = gb2312 when starting MySQLd.

10. wait_timeout:

The number of seconds that the server waits for action on a connection before closing it. The default value is 28800. I will change it to 7200.

Note: you can modify the parameters by modifying the/etc/my. cnf file and restarting MySQL. This is a relatively cautious job. The above results are just some of my views. You can further modify them based on your host's Hardware situation, especially the memory size.

It is said that this is the master to optimize the MySQL database performance for your reference, the number of connections: max_connections = 1500 can be changed based on the server performance.

# Set-variable = connect_timeout = 5

# Set-variable = wait_timeout = 5

We recommend that you enable this feature. servers with heavy workload can reduce the connection duration.

  1. [MySQLd]  
  2. basedir=D:/MySQL  
  3. #bind-address=ip 
  4. datadir=D:/MySQL/data  
  5. #language=D:/MySQL/share/your language directory  
  6. #slow query log#=  
  7. #tmpdir#=  
  8. #port=3306 
  9. set-variable = max_connections=1500  
  10. skip-locking  
  11. #skip-networking  
  12. set-variable = key_buffer=384M  
  13. set-variable = max_allowed_packet=1M  
  14. set-variable = table_cache=512  
  15. set-variable = sort_buffer=2M  
  16. set-variable = record_buffer=2M  
  17. set-variable = thread_cache=8  
  18. # Try number of CPU's*2 for thread_concurrency  
  19. set-variable = thread_concurrency=8  
  20. set-variable = myisam_sort_buffer_size=64M  
  21. #set-variable = connect_timeout=5  
  22. #set-variable = wait_timeout=5  
  23. server-id = 1 
  24. [isamchk]  
  25. set-variable = key_buffer=128M  
  26. set-variable = sort_buffer=128M  
  27. set-variable = read_buffer=2M  
  28. set-variable = write_buffer=2M  
  29. [myisamchk]  
  30. set-variable = key_buffer=128M  
  31. set-variable = sort_buffer=128M  
  32. set-variable = read_buffer=2M  
  33. set-variable = write_buffer=2M  
  34. [WinMySQLadmin]  
  35. Server=D:/MySQL/bin/MySQLd-nt.exe  

The above content is an introduction to optimizing the performance of MySQL databases. I hope you will have some gains.

Related Article

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: 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.