innodb_flush_method
How InnoDB opens and flushes data and log files.
- 預設
O_DIRECT on Linux- Range
- fsync, O_DSYNC, littlesync, nosync, O_DIRECT, O_DIRECT_NO_FSYNC (Unix)
- Restart needed
- 是
- Default checked on
- MySQL 8.4 LTS
其作用
O_DIRECT bypasses the OS page cache for data files, so pages are not cached twice; fsync uses buffered I/O. On Windows the choices are unbuffered and normal.
預設值
O_DIRECT on Linux. O_DIRECT where supported since MySQL 8.4 (fsync in 8.0). Windows uses unbuffered.
Check the current value
SHOW GLOBAL VARIABLES LIKE 'innodb_flush_method'; SELECT VARIABLE_NAME, VARIABLE_SOURCE, MIN_VALUE, MAX_VALUE, SET_TIME FROM performance_schema.variables_info WHERE VARIABLE_NAME = 'innodb_flush_method';
Change it
SET PERSIST_ONLY innodb_flush_method = O_DIRECT; -- then restart mysqld (or set it under [mysqld] in my.cnf)
Restart required: the variable is read-only at runtime (SET GLOBAL fails with error 1238). Stage it with SET PERSIST_ONLY or under [mysqld] in my.cnf.
When to change it
Rarely in 8.4. Check it on servers upgraded from 8.0 with an old my.cnf that still says fsync.
What can go wrong
nosync and littlesync are for testing only. On a file system without O_DIRECT support, such as tmpfs, InnoDB logs a warning and carries on with buffered I/O.
Questions about innodb_flush_method
What is the default value of innodb_flush_method in MySQL?
O_DIRECT on Linux. O_DIRECT where supported since MySQL 8.4 (fsync in 8.0). Windows uses unbuffered.
Does changing innodb_flush_method require a restart?
Yes. Restart required: the variable is read-only at runtime (SET GLOBAL fails with error 1238). Stage it with SET PERSIST_ONLY or under [mysqld] in my.cnf.
When should I change innodb_flush_method?
Rarely in 8.4. Check it on servers upgraded from 8.0 with an old my.cnf that still says fsync.
Back to all MySQL settings, or check the MySQL manual for every option.
Check innodb_flush_method on your own server
SQLly runs the query above against MySQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.