Home Database Mysql Tutorial MySQL服务优化参数设置参考_MySQL

MySQL服务优化参数设置参考_MySQL

Jun 01, 2016 pm 01:31 PM
Influence buffer Universal

bitsCN.com

MySQL服务优化参数设置参考

 

l 通用类:

 

key_buffer_size

 

含义:用于索引块的缓冲区大小,增加它可得到更好处理的索引(对所有读和多重写)。

 

影响:对于MyISAM表的影响不是很大,MyISAM会使用系统的缓存来存储数据,所以大量使用MyISAM表的机器内存很快就会耗尽。但是,如果你将该值设得过大(例如,大于总内存的50%),系统将转换为页并变得极慢。MySQL依赖操作系统来执行数据读取时的文件系统缓存,因此你必须为文件系统缓存留一些空间。

 

建议:先设置为内存的25%,观察性能变化。

 

table_open_cache

 

含义:为所有线程打开表的数量。

 

影响:增加该值能增加mysqld要求的文件描述符的数量。可以避免频繁的打开数据表产生的开销。打开一个表的开销可能很大,因为MyISAM会把MYI文件的文件头标识为正在使用,所以在内存中做这个操作比较好。,因为每个线程都需要打开表,连接数越大这个值要越大。

 

建议:我们有300多个表的话,大约2048差不多了。

 

 

 

thread_cache_size

 

含义:缓存可重用的线程数。

 

影响:这个参数设置线程的缓存,线程的创建和销毁的开销可能很大,因为每个线程的连接/断开都需要。如果应用程序中有大量的跳跃并发连接并且线程较多的话,就要加大它的值。它的目的是在通常的操作中无需创建新线程。

 

建议:通常至少设置为16。

 

 

 

query_cache_size

 

含义:指定MySQL查询结果缓冲区的大小。

 

影响:如果应用程序有大量读,而且没有应用程序级别的缓存,那么这很有用。不过不要设置太大,因为维护它也需要不少开销,这会导致MySQL变慢。

 

建议:通常设置为 32-512Mb。设置完之后最好是跟踪一段时间,查看是否运行良好。在一定的负载压力下,如果缓存命中率太低了,就启用它,如果命中率已经不错了,就可以把他调小一点。对于2G的内存,先从16M开始,一倍一倍的增加,直到命中率比较稳定为止。

 

query_cache_limit

 

含义:缓存单条SQL的结果集上限。默认4KB。

 

影响:当一条SQL返回的结果集大于这个限制的时候,将不被MySQL缓存。

 

建议:设置为1M即可。

 

query_cache_min_res_unit

 

含义:缓存为每个数据集存放的最小内存大小,默认4KB。

 

影响:如果太小的话,将会导致MySQL经常访问内存块去获取信息,如果设置太大则浪费内存。

 

建议:如果SQL返回的结果集都很小的话,参数也可以调小一点,避免内存浪费。如果结果集大部分都大于4KB的话,则考虑加大参数。

 

back_log

 

含义:在MySQL的连接请求等待队列中允许存放的最大连接请求数。系统默认值为50。

 

影响:如果系统在一个短时间内有很多连接,则需要增大该参数的值,该参数值指定到来的TCP/IP连接的侦听队列的大小。不同的操作系统在这个队列大小上有它自 己的限制。试图设定back_log高于你的操作系统的限制将是无效的。

 

建议:对于Linux系统推荐设置为小于512的整数。

 

sort_buffer_size

 

含义:为每个需要进行排序的线程分配该大小的一个缓冲区。

 

影响:增加这值加速ORDER BY或GROUP BY操作。不过该参数对应的分配内存是每连接独占的,如果有100个连接,那么实际分配的总共排序缓冲区大小为100×sort_buffer_size。

 

建议:一般设置为2M观察变化再调整。

 

read_buffer_size

 

含义:顺序查询操作所能使用的缓冲区大小。

 

影响:和sort_buffer_size一样,该参数对应的分配内存也是每连接独享。

 

建议:一般设置为2M再观察变化。

 

read_rnd_buffer_size

 

含义:随机查询操作所能使用的缓冲区大小。

 

影响:每个线程独享。

 

建议:一般设置为2M再观察变化。

 

query_cache_type

 

含义:查询缓冲类型。

 

影响:为1是使用缓冲,2是除非使用SQL_CACHE才进行缓冲。对于缓冲而言,数据并不是实时的,有一定的延时。但是对于实时性要求不高的查询短时间内多次执行,是不划算的,这个时候就需要缓存。并且缓存中是区分空格和大小写的,如果大小写不一致和空格不一致,也会认为是不同的SQL,不会利用到缓存。虽然不设置查询缓冲,有时可能带来性能上的损失,但有一些SQL语句需要实时地查询数据,或并不经常使用(可能一天就执行一两次),这样就需要把缓冲关了,可以采用临时关闭的方法SELECT SQL_NO_CACHE。

 

建议:一般设置为1。

 

l MyISAM类:

 

myisam_sort_buffer_size

 

MyISAM表发生变化时重新排序所需的缓冲。一般64M足矣。

 

l InnoDB类:

 

innodb_buffer_pool_size

 

对InnoDB的效率影响很大。因为InnoDB会把尽可能多的数据和索引缓存在缓冲区,这个类似与Oracle的Buffer Pool:如果只采用InnoDB,可以把这个参数调大一点,大约内存的70%左右。

 

当然,如果数据量不会暴增并且不是特别大,这个参数还是不要太大了,浪费空间。

 

innodb_additional_pool_size

 

对数据库性能影响不是很大,至少内存足够的机器上不会有什么影响。

 

innodb_log_file_size

 

在高写入负载尤其是数据集很大的时候,这个值非常重要,值越高性能越好,不过可能会增加数据恢复的时候。我设置为128M。

 

innodb_log_buffer_size

 

默认的设置在中等强度的写入负载及短事物处理时,性能还可以。但是存在大量更新操作或者负载较大时,就要慢慢增加这个参数的值了。不过不要设置太大,会浪费内存。它每秒都会刷新一次,所以不用设置超过1s所需的内存空间,16M足够了。

 

innodb_flush_logs_at_trx_commit

 

这个参数对InnoDB及其重要,设置不好的话会比MyISAM慢1000倍!默认是1,这就是说每次更新事务都会被提交到磁盘,这是非常消耗资源的,硬盘和内存的速度是明显数量级的差距。

 

设置为0是最快的,但是很不安全,全部在缓存中,一掉电全没了。

 

设置为1很不好,每次都去写硬盘,没有必要。

 

设置为2是比较好的,日志不刷新到磁盘上,只刷新到操作系统缓存上。然后每秒钟写缓存。相对于现在数据库每秒4K条左右的SQL,性能已经可以提高不少。

 

bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to Download Drivers for Universal PnP Monitors: 5 Ways How to Download Drivers for Universal PnP Monitors: 5 Ways Apr 21, 2023 pm 08:55 PM

If you have recently upgraded to Windows 10 or Windows 11, you may need to download a universal PnP monitor driver on your PC. Therefore, we have come up with a tutorial that will tell you more about Universal PnP Monitor and some quick ways to download and install Universal PnP Drivers on Windows. You may need to download drivers for most monitor brands, including the AcerGenericPnP monitor driver. When looking for monitor types in Device Manager or under the Monitors tab of the display adapter properties, you may notice Generic PnP Monitor. Chances are you'll find it in dual-monitor setups on both laptops and desktops. Down

VBOX_E_OBJECT_NOT_FOUND(0x80bb0001)VirtualBox error VBOX_E_OBJECT_NOT_FOUND(0x80bb0001)VirtualBox error Mar 24, 2024 am 09:51 AM

When trying to open a disk image in VirtualBox, you may encounter an error indicating that the hard drive cannot be registered. This usually happens when the VM disk image file you are trying to open has the same UUID as another virtual disk image file. In this case, VirtualBox displays error code VBOX_E_OBJECT_NOT_FOUND(0x80bb0001). If you encounter this error, don’t worry, there are some solutions you can try. First, you can try using VirtualBox's command line tools to change the UUID of the disk image file, which will avoid conflicts. You can run the command `VBoxManageinternal

How effective is receiving phone calls using airplane mode? How effective is receiving phone calls using airplane mode? Feb 20, 2024 am 10:07 AM

What happens when someone calls in airplane mode? Mobile phones have become one of the indispensable tools in people's lives. It is not only a communication tool, but also a collection of entertainment, learning, work and other functions. With the continuous upgrading and improvement of mobile phone functions, people are becoming more and more dependent on mobile phones. With the advent of airplane mode, people can use their phones more conveniently during flights. However, some people are worried about what impact other people's calls in airplane mode will have on the mobile phone or the user? This article will analyze and discuss from several aspects. first

Logger buffer size what is log used for Logger buffer size what is log used for Mar 13, 2023 pm 04:27 PM

The function is to provide engineers with feedback on usage information and records to facilitate problem analysis (used during development); because users themselves do not often generate upload logs, they are useless to users. The logging buffer is a small, temporary area used for short-term storage of change vectors for redo logs to be written to disk. A log buffer write to disk is a batch of change vectors from multiple transactions. Even so, the change vector in the log buffer is written to disk in near real-time, and when the session issues a COMMIT statement, the log buffer write operation is performed in real time.

How to turn off the comment function on TikTok? What happens after turning off the comment function on TikTok? How to turn off the comment function on TikTok? What happens after turning off the comment function on TikTok? Mar 23, 2024 pm 06:20 PM

On the Douyin platform, users can not only share their life moments, but also interact with other users. Sometimes the comment function may cause some unpleasant experiences, such as online violence, malicious comments, etc. So, how to turn off the comment function of TikTok? 1. How to turn off the comment function of Douyin? 1. Log in to Douyin APP and enter your personal homepage. 2. Click "I" in the lower right corner to enter the settings menu. 3. In the settings menu, find "Privacy Settings". 4. Click "Privacy Settings" to enter the privacy settings interface. 5. In the privacy settings interface, find "Comment Settings". 6. Click "Comment Settings" to enter the comment setting interface. 7. In the comment settings interface, find the "Close Comments" option. 8. Click the "Close Comments" option to confirm closing comments.

File Inclusion Vulnerabilities in Java and Their Impact File Inclusion Vulnerabilities in Java and Their Impact Aug 08, 2023 am 10:30 AM

Java is a commonly used programming language used to develop various applications. However, just like other programming languages, Java has security vulnerabilities and risks. One of the common vulnerabilities is the file inclusion vulnerability (FileInclusionVulnerability). This article will explore the principle, impact and how to prevent this vulnerability. File inclusion vulnerabilities refer to the dynamic introduction or inclusion of other files in the program, but the introduced files are not fully verified and protected, thus

The impact of data scarcity on model training The impact of data scarcity on model training Oct 08, 2023 pm 06:17 PM

The impact of data scarcity on model training requires specific code examples. In the fields of machine learning and artificial intelligence, data is one of the core elements for training models. However, a problem we often face in reality is data scarcity. Data scarcity refers to the insufficient amount of training data or the lack of annotated data. In this case, it will have a certain impact on model training. The problem of data scarcity is mainly reflected in the following aspects: Overfitting: When the amount of training data is insufficient, the model is prone to overfitting. Overfitting refers to the model over-adapting to the training data.

Six pictures explain Linux zero-copy technology clearly Six pictures explain Linux zero-copy technology clearly Feb 22, 2024 pm 06:40 PM

Hello everyone, today let us talk about Linux zero-copy technology. We will use the sendfile system call as an entry point to deeply explore the basic principles of zero-copy technology. The core idea of ​​zero-copy technology is to minimize the copying of data between memories and improve the efficiency and performance of data transmission by optimizing the data transmission path. 1. Introduction to zero-copy technology Linux zero-copy technology is a technology used to optimize data transmission. It improves the efficiency of data transmission by reducing the number of data copies between kernel mode and user mode. During the process of data transmission, it is usually necessary to copy the data from the kernel buffer to the application buffer, and then from the application buffer to the buffer of the network device before the transmission can be completed. Advantages of zero-copy technology

See all articles