MySQL 4G memory server configuration optimization

MySQL 4G memory server configuration optimization

As the number of visits to the company's website increases (over 100,000 PV per day), MySQL naturally becomes a bottleneck. Regarding MySQL optimization, the most basic thing is the optimization of MySQL system parameters.

MySQL has the greatest impact on web architecture performance and is also a key core part. Whether the MySQL settings are properly optimized directly affects the speed and carrying capacity of the web! At the same time, MySQL is also the most difficult part to optimize. Not only does it require some MySQL professional knowledge, but it also requires long-term observation and statistics and judgment based on experience, and then setting reasonable parameters. Next, let's take a look at some of the basics of MySQL optimization and the optimization of MySQL itself (my.cnf).

We introduce some parameters that have a greater impact on performance. Since the optimization settings of the my.cnf file are closely related to the server hardware configuration, we specify a common 2U server hardware environment: CPU: 2 Intel Xeon 2.4GHz Memory: 4GB DDR Hard disk: SCSI.

Next, we will explain based on the above hardware configuration and an optimized my.cnf:

[mysqld] 
 port = 3306 
 serverid = 1 
 socket = /tmp/mysql.sock 
 skip-locking 
#Avoid external locking of MySQL, reduce the chance of errors and enhance stability. 
skip-name-resolve 
#Disable MySQL from performing DNS resolution on external connections. Using this option can eliminate the time it takes for MySQL to perform DNS resolution. But please note that if this option is turned on, all remote host connection authorizations must use the IP address method, otherwise MySQL will not be able to process the connection request normally!
back_log = 384 
The value of the #back_log parameter indicates how many requests can be stored in the stack in a short period of time before MySQL temporarily stops responding to new requests. If the system has many connections in a short period of time, you need to increase the value of this parameter, which specifies the size of the listening queue for incoming TCP/IP connections. Different operating systems have their own limitations on this queue size. Attempting to set back_log higher than your operating system's limit will have no effect. The default value is 50. For Linux systems, it is recommended to set this parameter to an integer less than 512.
key_buffer_size = 256M 
#key_buffer_size specifies the buffer size used for indexing. Increasing it can get better index processing performance. For servers with around 4GB of memory, this parameter can be set to 256M or 384M. Note: If this parameter value is set too high, the overall efficiency of the server will be reduced!
max_allowed_packet = 4M 
 thread_stack = 256K 
 table_cache = 128K 
 sort_buffer_size = 6M 
#Query the buffer size that can be used when sorting. Note: The allocated memory corresponding to this parameter is exclusive to each connection. If there are 100 connections, the total sort buffer size actually allocated is 100 × 6 = 600MB. Therefore, for servers with around 4GB of memory, the recommended setting is 6-8M.
read_buffer_size = 4M 
#The buffer size that can be used for read query operations. Like sort_buffer_size, the allocated memory corresponding to this parameter is also exclusive to each connection.
join_buffer_size = 8M 
#The buffer size that can be used for joint query operations. Like sort_buffer_size, the allocated memory corresponding to this parameter is also exclusive to each connection.
myisam_sort_buffer_size = 64M 
 table_cache = 512 
 thread_cache_size = 64 
 query_cache_size = 64M 
#Specify the size of the MySQL query buffer. You can observe in the MySQL console that if the value of Qcache_lowmem_prunes is very large, it indicates that the buffer is often insufficient; if the value of Qcache_hits is very large, it indicates that the query buffer is used very frequently. If the value is small, it will affect the efficiency. In this case, you can consider not using the query buffer; Qcache_free_blocks, if the value is very large, it indicates that there are a lot of fragments in the buffer.
tmp_table_size = 256M 
 max_connections = 768 
#Specify the maximum number of connection processes allowed by MySQL. If the error message "Too Many Connections" often appears when accessing the forum, you need to increase the value of this parameter.
max_connect_errors = 10000000 
 wait_timeout = 10 
#Specify the maximum connection time for a request. For a server with about 4GB of memory, it can be set to 5-10. 
thread_concurrency = 8 
#The value of this parameter is the number of logical CPUs on the server*2. In this example, the server has 2 physical CPUs, and each physical CPU supports HT hyperthreading, so the actual value is 4*2=8
 skip-networking 
#Enabling this option can completely shut down the TCP/IP connection mode of MySQL. If the WEB server accesses the MySQL database server via a remote connection, do not enable this option! Otherwise the connection will not work!
table_cache=1024 
#The larger the physical memory, the larger the setting. The default is 2402, and the best setting is 512-1024 innodb_additional_mem_pool_size=4M 
#Default is 2M 
 innodb_flush_log_at_trx_commit=1 
#Set to 0 to wait until the innodb_log_buffer_size queue is full before storing them all together. The default value is 1 
 innodb_log_buffer_size=2M 
#Default is 1M 
 innodb_thread_concurrency=8 
#Set it to the number of CPUs on your server. The default value is usually 8. 
 key_buffer_size=256M 
#The default is 218, adjust to 128 for the best tmp_table_size=64M 
#The default is 16M, adjust to 64-256 for the best read_buffer_size=4M 
#Default is 64K 
 read_rnd_buffer_size=16M 
#Default is 256K 
 sort_buffer_size=32M 
#Default is 256K 
 thread_cache_size=120 
#Default is 60 
 query_cache_size=32M

Notice:

1. If Key_reads is too large, you should increase Key_buffer_size in my.cnf to keep Key_reads/Key_read_requests at least 1/100, the smaller the better.

2. If Qcache_lowmem_prunes is large, increase the value of Query_cache_size.

Summarize

The above is the MySQL 4G memory server configuration optimization introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Detailed explanation of the usage of MySQL memory tables and temporary tables
  • Summary of MySQL 8.0 memory-related parameters
  • Solutions to MySQL OOM (memory overflow)
  • Detailed explanation of how to reduce memory usage in MySql
  • Detailed explanation of how to view MySQL memory usage
  • Detailed explanation of the my.ini Chinese configuration scheme for MySql optimization: InnoDB, 4GB memory, and multiple queries
  • Perfect solution to MySQL common insufficient memory startup failure
  • Test and solution for MySQL's large memory usage and high CPU usage
  • Solution to high memory usage when starting MySQL 5.6
  • Detailed analysis of MySQL 8.0 memory consumption

<<:  How to install Docker on Raspberry Pi

>>:  Summary of several commonly used string methods in JavaScript (must-read for beginners)

Recommend

Flex layout achieves fixed number of rows per line + adaptive layout

This article introduces the flex layout to achiev...

Web page layout should consider IE6 compatibility issues

The figure below shows the browser viewing rate i...

mysql startup failure problem and scenario analysis

1. One-stop solution 1. Problem analysis and loca...

Is it necessary to give alt attribute to img image tag?

Do you add an alt attribute to the img image tag? ...

Learn how to write neat and standard HTML tags

Good HTML code is the foundation of a beautiful w...

Fixed table width table-layout: fixed

In order to make the table fill the screen (the re...

Detailed tutorial on installing Mysql5.7.19 on Centos7 under Linux

1. Download MySQL URL: https://dev.mysql.com/down...

Issues with upgrading Python and installing Mongodb drivers under Centos

Check the Python version python -V If it is below...

MySQL statement arrangement and summary introduction

SQL (Structured Query Language) statement, that i...

Object-Oriented Programming with XHTML and CSS

<br />If only XHTML and CSS were object-orie...

202 Free High Quality XHTML Templates (1)

Here 123WORDPRESS.COM presents the first part of ...

Introduction to the functions and usage of value and name attributes in Html

1. The value used in the button refers to the text...