Get the App
SLTechnology News&Howtos  ›  Database  › 

How to configure swap in MySQL

Shulou Source: shulou.com Published: 2022-05-31 19:11:29 09月16日 Update

This article mainly explains "how to configure swap in MySQL". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to configure swap in MySQL.

Swappiness

Swappiness is a parameter that controls the relative weight given to swapping out runtime memory, as opposed to dropping pages from the system. Swappiness can be set to values between 0 and 100 inclusive. A low value causes the kernel to avoid swapping, a higher value causes the kernel to try to use swap space. The default value is60, and for most desktop systems, setting it to 100may affect the overall performance, whereas setting it lower (even 0) may decrease response latency.

It probably means: Swappiness linuxswappiness0~10060swapswappiness1000

With kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over, it is likely better to use 1 for cases where 0 used to be optimal

In kernel version 3.5 and above and RHEL/CentOS kernels kernel version 2.6.32-303.el6 and above, it is recommended to use 1 to replace the effect of swappiness=0 in previous kernel versions.

This change is specifically prompted in many materials, such as the RHEL official:

MySQLInnoDBLinuxCPUIO InnoDBcacheInnoDB

MySQLvm.swappiness=0

OSvm.swappiness = 0swapswapswap

3.5 RHEL/CentOS kernels2.6.32-303vm.swappiness = 0swapnr_free + nr_filebacked

< high watermarkswapswapLinuxOOMkillMySQL wiki 解决办法 1、尽量保证Linux操作系统还有足够的内存 2、针对MySQL的服务器OS: 之vm.swappiness=0 3.5以及以上和 RHEL/CentOS kernels内核版本2.6.32-303.el6以及以上),建议设置vm.swappiness=1 3、考虑设置 /proc/(pidof -s mysqld)/oom_adj为较小的值来尽量避免MySQL由于内存不足而被关闭。 值的范围为-16~15,"-17"是一个特殊的值。如果设置为-17,就会禁止OOM Killer发出的信号(从Linux 2.6.12开始支持设置-17)。 例如:echo -15 >

/ proc/ (pidof-s mysqld) / oom_score_adj

The method of modifying swappiness

# temporary modification

# Set the swappiness value as root

Echo 10 > / proc/sys/vm/swappiness

# Alternatively, run this

Sysctl-w vm.swappiness=10

# Verify the change

Cat / proc/sys/vm/swappiness

ten

# Alternatively, verify the change

Sysctl vm.swappiness

Vm.swappiness = 10

# permanent entry into force requires modification of configuration file sysctl.conf

/ etc/sysctl.conf

Vm.swappiness = 10

Modify the oom_ adjunct value of mysql

# cat / proc/ (pidof-s mysqld) / oom_score_adj

0

# echo-15 > / proc/ (pidof-s mysqld) / oom_score_adj

# of course, you can completely close OOM killer if necessary (not recommended for production environments):

# sysctl-w vm.overcommit_memory=2

# echo "vm.overcommit_memory=2" > > / etc/sysctl.conf

Https://en.wikipedia.org/wiki/Swappiness#cite_note-2

Https://www.percona.com/blog/2014/04/28/oom-relation-vm-swappiness0-new-kernel/

Http://blog.csdn.net/longxibendi/article/details/38146521

Http://www.vpsee.com/2013/10/how-to-configure-the-linux-oom-killer/

Thank you for reading, the above is the content of "how to configure swap in MySQL". After the study of this article, I believe you have a deeper understanding of how to configure swap in MySQL, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Configuration kernel version learning memory content suggestion special operating system signal method official that is idea situation meaning effect file article method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB macOS vpn NVidia Linux