Copyright (C) 2000-2012 |
GNU Info (mysql.info)Option filesmy.cnf Option Files ------------------- MySQL can, since Version 3.22, read default startup options for the server and for clients from option files. MySQL reads default options from the following files on Unix: *Filename* *Purpose* `/etc/my.cnf' Global options `DATADIR/my.cnf' Server-specific options `defaults-extra-file' The file specified with -defaults-extra-file=# `~/.my.cnf' User-specific options `DATADIR' is the MySQL data directory (typically `/usr/local/mysql/data' for a binary installation or `/usr/local/var' for a source installation). Note that this is the directory that was specified at configuration time, not the one specified with `--datadir' when `mysqld' starts up! (`--datadir' has no effect on where the server looks for option files, because it looks for them before it processes any command-line arguments.) MySQL reads default options from the following files on Windows: *Filename* *Purpose* `windows-system-directory\my.ini'Global options `C:\my.cnf' Global options `C:\mysql\data\my.cnf' Server-specific options Note that on Windows, you should specify all paths with `/' instead of `\'. If you use `\', you need to specify this twice, as `\' is the escape character in MySQL. MySQL tries to read option files in the order listed above. If multiple option files exist, an option specified in a file read later takes precedence over the same option specified in a file read earlier. Options specified on the command line take precedence over options specified in any option file. Some options can be specified using environment variables. Options specified on the command line or in option files take precedence over environment variable values. Note: Environment variables. The following programs support option files: `mysql', `mysqladmin', `mysqld', `mysqldump', `mysqlimport', `mysql.server', `myisamchk', and `myisampack'. You can use option files to specify any long option that a program supports! Run the program with `--help' to get a list of available options. An option file can contain lines of the following forms: `#comment' Comment lines start with `#' or `;'. Empty lines are ignored. `[group]' `group' is the name of the program or group for which you want to set options. After a group line, any `option' or `set-variable' lines apply to the named group until the end of the option file or another group line is given. `option' This is equivalent to `--option' on the command line. `option=value' This is equivalent to `--option=value' on the command line. `set-variable = variable=value' This is equivalent to `--set-variable variable=value' on the command line. This syntax must be used to set a `mysqld' variable. The `client' group allows you to specify options that apply to all MySQL clients (not `mysqld'). This is the perfect group to use to specify the password you use to connect to the server. (But make sure the option file is readable and writable only by yourself.) Note that for options and values, all leading and trailing blanks are automatically deleted. You may use the escape sequences `\b', `\t', `\n', `\r', `\\', and `\s' in your value string (`\s' == blank). Here is a typical global option file: [client] port=3306 socket=/tmp/mysql.sock [mysqld] port=3306 socket=/tmp/mysql.sock set-variable = key_buffer_size=16M set-variable = max_allowed_packet=1M [mysqldump] quick Here is typical user option file: [client] # The following password will be sent to all standard MySQL clients password=my_password [mysql] no-auto-rehash set-variable = connect_timeout=2 [mysqlhotcopy] interactive-timeout If you have a source distribution, you will find sample configuration files named `my-xxxx.cnf' in the `support-files' directory. If you have a binary distribution, look in the `DIR/support-files' directory, where `DIR' is the pathname to the MySQL installation directory (typically `/usr/local/mysql'). Currently there are sample configuration files for small, medium, large, and very large systems. You can copy `my-xxxx.cnf' to your home directory (rename the copy to `.my.cnf') to experiment with this. All MySQL clients that support option files support the following options: -no-defaults Don't read any option files. -print-defaults Print the program name and all options that it will get. -defaults-file=full-path-to-default-fileOnly use the given configuration file. -defaults-extra-file=full-path-to-default-fileRead this configuration file after the global configuration file but before the user configuration file. Note that the above options must be first on the command line to work! `--print-defaults' may however be used directly after the `--defaults-xxx-file' commands. Note for developers: Option file handling is implemented simply by processing all matching options (that is, options in the appropriate group) before any command-line arguments. This works nicely for programs that use the last instance of an option that is specified multiple times. If you have an old program that handles multiply-specified options this way but doesn't read option files, you need add only two lines to give it that capability. Check the source code of any of the standard MySQL clients to see how to do this. In shell scripts you can use the `my_print_defaults' command to parse the config files: shell> my_print_defaults client mysql --port=3306 --socket=/tmp/mysql.sock --no-auto-rehash The above output contains all options for the groups 'client' and 'mysql'. automatically generated by info2www version 1.2.2.9 |