MySQL Server Configuration
MySQL Server Configuration Files
Most MySQL programs can read startup options from option files (sometimes called configuration files). Option files provide a convenient way to specify commonly used options so that they need not be entered on the command line each time you run a program.
To determine whether a program reads option files, invoke it with the --help option. (For mysqld, use --verbose and --help.) If the program reads option files, the help message indicates which files it looks for and which option groups it recognizes.
Configuration Files on Windows
On Windows, MySQL programs read startup options from the files shown in the following table, in the specified order (files listed first are read first, files read later take precedence).
| File Name | Purpose |
|---|---|
%WINDIR%\my.ini, %WINDIR%\my.cnf |
Global options |
C:\my.ini, C:\my.cnf |
Global options |
BASEDIR\my.ini, BASEDIR\my.cnf |
Global options |
defaults-extra-file |
The file specified with --defaults-extra-file, if any |
%APPDATA%\MySQL\.mylogin.cnf |
Login path options (clients only) |
DATADIR\mysqld-auto.cnf |
System variables persisted with SET PERSIST or SET PERSIST_ONLY (server only) |
%WINDIR%represents the location of your Windows directory. This is commonlyC:\WINDOWS. You can runecho %WINDIR%to view the location.%APPDATA%represents the value of the Windows application data directory.C:\Users\{userName}\AppData\Roaming.BASEDIRrepresents the MySQL base installation directory. When MySQL 8.0 has been installed using MySQL Installer, this is typicallyC:\PROGRAMDIR\MySQL\MySQL Server 8.0in whichPROGRAMDIRrepresents the programs directory (usuallyProgram Filesfor English-language versions of Windows). Although MySQL Installer places most files underPROGRAMDIR, it installsmy.iniunder theC:\ProgramData\MySQL\MySQL Server 8.0\directory (DATADIR) by default.DATADIRrepresents the MySQL data directory. As used to findmysqld-auto.cnf, its default value is the data directory location built in when MySQL was compiled, but can be changed by--datadirspecified as an option-file or command-line option processed beforemysqld-auto.cnfis processed. By default, thedatadiris set toC:/ProgramData/MySQL/MySQL Server 8.0/Datain theBASEDIR\my.ini(C:\ProgramData\MySQL\MySQL Server 8.0\my.ini). You also can get theDATADIRlocation by running the SQL statementSELECT @@datadir;.
After you installed MySQL 8.0 on Windows, you only have a configuration file BASEDIR\my.ini (actually C:\ProgramData\MySQL\MySQL Server 8.0\my.ini).
Configuration Files on Unix-Like Systems
On Unix and Unix-like systems, MySQL programs read startup options from the files shown in the following table, in the specified order (files listed first are read first, files read later take precedence).
Note: On Unix platforms, MySQL ignores configuration files that are world-writable. This is intentional as a security measure.
| File Name | Purpose |
|---|---|
/etc/my.cnf |
Global options |
/etc/mysql/my.cnf |
Global options |
SYSCONFDIR/my.cnf |
Global options |
$MYSQL_HOME/my.cnf |
Server-specific options (server only) |
defaults-extra-file |
The file specified with --defaults-extra-file, if any |
~/.my.cnf |
User-specific options |
~/.mylogin.cnf |
User-specific login path options (clients only) |
DATADIR/mysqld-auto.cnf |
System variables persisted with SET PERSIST or SET PERSIST_ONLY (server only) |
SYSCONFDIRrepresents the directory specified with theSYSCONFDIRoption to CMake when MySQL was built. By default, this is theetcdirectory located under the compiled-in installation directory.MYSQL_HOMEis an environment variable containing the path to the directory in which the server-specificmy.cnffile resides. IfMYSQL_HOMEis not set and you start the server using the mysqld_safe program, mysqld_safe sets it toBASEDIR, the MySQL base installation directory.DATADIRrepresents the MySQL data directory. As used to findmysqld-auto.cnf, its default value is the data directory location built in when MySQL was compiled, but can be changed by--datadirspecified as an option-file or command-line option processed beforemysqld-auto.cnfis processed. By default, thedatadiris set to/var/lib/mysqlin the/etc/my.cnfor/etc/mysql/mysql. You also can get theDATADIRlocation by running the SQL statementSELECT @@datadir;.
After you installed MySQL 8.0 on Linux, you only have a configuration file /etc/my.cnf.
Configuration File Inclusions
It is possible to use !include directives in option files to include other option files and !includedir to search specific directories for option files. For example, to include the /home/mydir/myopt.cnf file, use the following directive:
!include /home/mydir/myopt.cnf |
To search the /home/mydir directory and read option files found there, use this directive:
!includedir /home/mydir |
MySQL makes no guarantee about the order in which option files in the directory are read.
Note: Any files to be found and included using the !includedir directive on Unix operating systems must have file names ending in .cnf. On Windows, this directive checks for files with the .ini or .cnf extension.
Why would you put some directives into separate files instead of just keeping them all in /etc/my.cnf? For modularity.
If you want to deploy some sets of config directives in a modular way, using a directory of individual files is a little easier than editing a single file. You might make a mistake in editing, and accidentally change a different line than you intended.
Also removing some set of configuration options is easy if they are organized into individual files. Just delete one of the files under /etc/my.cnf.d, and restart mysqld, and then it’s done.
Common Configurations
Change port
[client] |