Using Option Files
MostMySQL programs can read startup options from option files (also sometimescalled configuration files). Option files provide a convenient way to specifycommonly used options so that they need not be entered on the command line eachtime you run a program. For the MySQL server, MySQL provides a number of preconfiguredoption files.
Todetermine whether a program reads option files, invoke it with the --help option. (For mysqld, use --verbose and --help.) If the program reads optionfiles, the help message indicates which files it looks for and which optiongroups it recognizes.
The .mylogin.cnf file that contains loginpath options is created by the mysql_config_editorutility. See Section 4.6.6, “mysql_config_editor — MySQLConfiguration Utility”. A “login path” is an optiongroup that permits only certain options: host, user,password, port and socket.Client programs specify which login path to read from .mylogin.cnf using the --login-path option.
To specifyan alternate file name, set the MYSQL_TEST_LOGIN_FILEenvironment variable.
Thisvariable is used by the mysql-test-run.pltesting utility, but also is recognized by
mysql_config_editor and by MySQL clients suchas mysql, mysqladmin, and so forth.
On Windows, MySQLprograms read startup options from the following files, in the specified order(top files are read first, later files take precedence).
File Name |
Purpose |
%PROGRAMDATA%\MySQL\MySQLServer5.6\my.ini, %PROGRAMDATA%\MySQL\MySQLServer5.6\my.cnf |
Global options |
%WINDIR%\my.ini, %WINDIR%\my.cnf |
Global options |
C:\my.ini, C:\my.cnf |
Global options |
INSTALLDIR\my.ini, INSTALLDIR\my.cnf |
Global options |
defaults-extra-file |
The file specified with --defaults-extra-file=file_name, if any |
%APPDATA%\MySQL \.mylogin.cnf |
Login path options |
On Unix, Linux and OSX, MySQL programs read startup options from the following files, in the specifiedorder (top files are read first, later files take precedence).
File Name |
Purpose |
/etc/my.cnf |
Global options |
/etc/mysql/my.cnf |
Global options |
SYSCONFDIR/my.cnf |
Global options |
$MYSQL_HOME/my.cnf |
Login path options |
defaults-extra-file |
The file specified with --defaults-extra-file=file_name, if any |
~/.my.cnf |
User-specific options |
~/.mylogin.cnf |
Login path options |
In tableitems, ~ representsthe current user's home directory (the value of $HOME).
SYSCONFDIR represents the directoryspecified with the SYSCONFDIR optionto CMake whenMySQL was built. By default, this is the etc directory located under the compiled-ininstallation directory.
MYSQL_HOME is an environment variablecontaining the path to the directory in which the
server-specificmy.cnf file resides. If MYSQL_HOME is not set and you startthe server using the mysqld_safe program,mysqld_safe attempts to set MYSQL_HOME as follows:
• Let BASEDIR and DATADIR represent the path namesof the MySQL base directory and data directory, respectively.
• Ifthere is a my.cnf file in DATADIR but not in BASEDIR, mysqld_safe sets MYSQL_HOME to DATADIR.
•Otherwise, if MYSQL_HOME is notset and there is no my.cnf filein DATADIR, mysqld_safe sets MYSQL_HOME to BASEDIR.
In MySQL5.6, use of DATADIR asthe location for my.cnf isdeprecated.
Typically,DATADIR is/usr/local/mysql/data for abinary installation or /usr/local/var fora source installation. This is the data directory location that was specifiedat configuration time, not the one specified with the --datadir option when mysqld starts. Use of --datadir at runtime has
no effecton where the server looks for option files, because it looks for them beforeprocessing any options.
MySQLlooks for option files in the order just described and reads any that exist. Ifan option file that you want to use does not exist, create it with a plain texteditor.
Ifmultiple instances of a given option are found, the last instance takesprecedence. There is one exception: For mysqld, the first instance ofthe --user option isused as a security precaution, to prevent a user specified in an option filefrom being overridden on the command line.