There is a parameter called swappiness in the Linux kernel. You can adjust how memory is used.
By default, this value is 60, which means that the kernel will provide more memory for the file system as a cache, or even swap the memory occupied by some programs into swap to free up memory.
This is just a conflict with the MySQL database using the InnoDB engine: The InnoDB buffer pool is inherently equivalent to the file system cache, which caches a portion of the database that has been read.
This part of memory usually does not modify the changes, so the operating system will be more inclined to swap out this part of memory into swap. This way, when MySQL really needs to innodb in the buffer
Data, the operating system needs to re-read the corresponding swap into memory, or even worse, it will swap other portions of memory to swap to maintain sufficient system memory (file system cache).
This makes the INNODB buffer not only accelerates, but is slower than not caching.
For this scenario, consider setting the swappiness parameter to 0: try to allocate memory to the program process (this is exactly the InnoDB buffer) rather than the file system cache.
The specific commands are as follows:
echo 0 > /proc/sys/vm/swappiness
An important kernel parameter for the MySQL database InnoDB engine swappiness