Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to optimize the performance of Database in MySQL

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces you how to optimize database performance in MySQL, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Key parameter one: back_log

The number of connections required for MySQL. This works when the main MySQL thread gets a lot of connection requests in a very short period of time, and then the main thread takes some (albeit short) time to check the connection and start a new thread.

The back_log value indicates how many requests can be stored on the stack in a short period of time before MySQL temporarily stops answering new requests. Only if you expect 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 listening queue for incoming TCP/ip connections. Your operating system has its own limits on the queue size. Trying to set the limit that back_log is higher than your operating system will not be valid.

When you look at your list of host processes and find a large number of 264084 | unauthenticated user | xxx.xxx.xxx.xxx | Connect | NULL | login | NULL processes to be connected, you need to increase the value of back_log. The default value is 50, and I'll change it to 500.

Key parameter 2: interactive_timeout

The number of seconds 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 _ real_connect (). The default value is 28800, and I'll change it to 7200.

Key parameter 3: key_buffer_size

The index block is buffered and shared by all threads. Key_buffer_size is the buffer size for index blocks, increasing it to get better-handled indexes (for all reads and multiple overrides) as much as you can afford. If you make it too big, the system will start to change pages and really slow down. The default is 8388600 (8m), and my MySQL host has 2GB memory, so I changed it to 402649088 (400MB).

Key parameter 4: max_connections

The number of simultaneous customers allowed. Increasing this value increases the number of file descriptors required by mysqld. This number should be increased, otherwise you will often see Too many connections errors. The default value is 100, and I'll change it to 1024.

Key parameter 5: record_buffer

Each thread that performs a sequential scan allocates a buffer of this size to each table it scans. If you do a lot of sequential scans, you may want to increase this value. The default value is 131072 (128K), which I changed to 16773120 (16m)

Key parameter 6: sort_buffer

Each thread that needs to sort allocates a buffer of that size. Increase this value to speed up ORDER BY or GROUP BY operations. The default value is 2097144 (2m), which I changed to 16777208 (16m).

Key parameter 7: table_cache

The number of open tables for all threads. Increasing this value increases the number of file descriptors required by mysqld. MySQL requires 2 file descriptors for each unique open table. The default value is 64, and I'll change it to 512.

Key parameter 8: thread_cache_size

The number of threads saved in that can be reused. If so, the new thread is fetched from the cache, and the customer's line is placed in the cache if there is space when the connection is disconnected. If there are many new threads, you can use the value of this variable to improve performance. By comparing the variables of the Connections and Threads_created states, you can see the effect of this variable. I set it to 80.

Key parameter 9: wait_timeout

The number of seconds the server waits for action on a connection before shutting it down. The default value is 28800, and I'll change it to 7200.

Note: parameters can be adjusted by modifying the / etc/my.cnf file and restarting MySQL. This is a more cautious work, and the above results are just some of my views, you can according to the hardware of your own host (especially the large memory

On how to optimize database performance in MySQL to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report