MySQL operation and maintenance 19-InnoDB temporary files

1. The role of temporary files

  • When sorting (ORDER BY or GROUP BY), MySQL usually uses 1 or more temporary files.
  • For certain SELECT queries, MySQL creates temporary SQL tables.
  • ALTER TABLE creates temporary tables in the same directory as the original table directory.

2. Location of temporary files

MySQL uses the value of the environment variable TMPDIR as the pathname of the directory where temporary files are saved. If TMPDIR is not set, then MySQL will use the system default, usually /tmp, /var/tmp, or /usr/tmp.

3. Precautions for temporary files

  • If the file system containing the temporary file directory is too small, you can use the "-tmpdir" option for mysqld, or modify the parameter tmpdir in the configuration file to specify a temporary file directory in the file system with enough space,
  • For sorting large amounts of data, the capacity of the temporary space may exceed the /tmp space. At this time, the execution of the query will fail, and an error record "sort abort" will appear in the MySQL error log. The solution is to optimize the query or set the temporary directory to another partition with enough space.
  • If the MySQL server is being used as a slave, then "--tmpdir" should not be set to point to a directory on the memory-based file system, because the temporary file directory will be emptied when the server host is restarted. For the slave server, some temporary files need to be retained when the machine is restarted, so that temporary tables can be copied or LOAD DATA INFILE operations can be performed.

4. Summary

  1. Temporary files are mainly used in query scenarios such as ORDER BY, GROUP BY, and table joins. ALTER TABLE operations will also create temporary tables in the same directory as the original table directory.
  2. MySQL uses the value of the environment variable TMPDIR as the pathname of the directory where temporary files are saved. If TMPDIR is not set, then MySQL will use the system default, usually /tmp, /var/tmp, or /usr/tmp.

おすすめ

転載: blog.csdn.net/oddrock/article/details/130173664
おすすめ