Chapter 64. Optimizing the MySQL Server

Table of Contents

System/Compile Time and Startup Parameter Tuning
Tuning Server Parameters
How Compiling and Linking Affects the Speed of MySQL
How MySQL Uses Memory
How MySQL uses DNS
SET Syntax

System/Compile Time and Startup Parameter Tuning

We start with the system level factors, because some of these decisions must be made very early. In other cases, a quick look at this section may suffice because it not that important for the big gains. However, it is always nice to have a feeling about how much one could gain by changing things at this level.

The default operating system to use is really important! To get the best use of multiple-CPU machines, you should use Solaris (because its threads implementation works really well) or Linux (because the 2.2 kernel has really good SMP support). Also, older Linux kernels have a 2G file-size limit by default. If you have such a kernel and a desperate need for files larger than 2G, you should get the LFS (large file system) patch for the ext2 filesystem. Other filesystems such as ReiserFS and XFS do not have this 2G limitation.

Because we have not run MySQL in production on that many platforms, we advise you to test your intended platform before choosing it, if possible.

Other tips:

  • If you have enough RAM, you could remove all swap devices. Some operating systems will use a swap device in some contexts even if you have free memory.

  • Use the --skip-external-locking MySQL option to avoid external locking. Note that this will not impact MySQL's functionality as long as you only run one server. Just remember to take down the server (or lock and flush the relevant tables) before you run myisamchk. On some systems this option is mandatory, because the external locking does not work in any case.

    The --skip-external-locking option is on by default as of MySQL 4.0. Before that, it is on by default when compiling with MIT-pthreads, because flock() isn't fully supported by MIT-pthreads on all platforms. It's also on default for Linux as Linux file locking are not yet safe.

    The only case when you can't use --skip-external-locking is if you run multiple MySQL servers (not clients) on the same data, or if you run myisamchk on the table without telling the server to flush and lock the tables first.

    You can still use LOCK TABLES/UNLOCK TABLES even if you are using --skip-external-locking.