MySQL - Option File

Options in option files are organized into groups, with each group preceded by a [group-name] line that names the group. Typically, the group name is the name of the program to which the group of options applies. The special group named [client] can be used for specifying options that you want all client program to use.

To write an option in an option file, use the long option format that you would use on the command line, but omit the lead dashes. If an option takes a value, spaces are allowed around the = sign, something that isn't true for options specified on the command line.

 [client]
  compress

 [mysql]
  safe-updates

On Unix, the file /etc/my.cnf serves as a global option file used by all users. You can set up your own user-specific option file by creating a file named .my.cnf in your home directory. The global file is read first.

To tell a program to read a single specific option file instead of the standard option files, use the —defaults-file=file_name option as the first option on the command line.

To tell a program to read a single specific option file in addition to the standard option files, use the —defaults-extra-file=file_name option as the first option on the command line.

To tell a program to ignore all option files, specify —no-defaults as the first option on the command line.

Option files can reference other files to be read for options using !include and !includedir directives:

  • A line that says !include file_name suspends processing of the current option file. The file file_name is read for additional options, and then processing of the suspended file resumes.
  • A line that says !includedir dir_name is similar except that the directory dir_name is searched for files that end with .cnf extention. Any such files are read for options, and then processing of the suspended file resumes.

If an option is specified multiple times, either in the same option file or in multiple option files, the option value that occurs last take precedence. Options specified on the command line take precedence over options found in option files.

.my.cnf:

[client]
host=192.168.11.92
use=porche
database=dbname
password=blah
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License