Using Option Files
Most MySQL programs can read startup option files(sometimes called configuration files).
Option files provide a convenient way to specify commonly used option so that they need not be entered on the command line each time you run a program.
Note
A MySQL program started with the --no-defaults
option reads no option files other than .mylogin.cnf
.
A server started with the persisted_globals_load
system variable disabled does not read mysqld-auto.cnf
.
Many option files are plain text files, created usingg any text editor.The exceptions are:
`The .mylogin.cnf file that contains login path option. This is an encrypted file created by the mysql_config_editor utility.
See Section 4.6.7, “mysql_config_editor — MySQL Configuration Utility”. A “login path” is an option group 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 specify an alternative login path file name, set the MYSQL_TEST_LOGIN_FILE
environment variable. This variable is used by the mysql-test-run.pl testing utility, but also is recognized by mysql_config_editor and by MySQL clients such as mysql, mysqladmin, and so forth.
`The mysqld-auto.cnf
file in the data directory. This JSON-format file contains persisted system variable settings. It is created by the server upon execution of SET PERSIST
or PERSIST_ONLY
statements. See Section 13.7.5.1, “SET Syntax for Variable Assignment”. Management of mysqld-auto.cnf
should be left to the server and not performed manually.
MySQL looks for option files in the order described in the following discussion and reads any that exist.
If an option file you want to use does not exist, create it using the appropriate method, as just discussed.
在option文件中,语法和命令行中的相似,但是可以省略开头的two dashes并且每行输入一个option.
空行被忽略.
1. #comment, ;comment
评论以#或者;开头. # 可以在行中评论.
2. [group] group是要设置options的program or group的名字
在group line后,任何option-setting lines可以应用于之前命名的group知道option文件结尾或者另一个group line is given.
group names大小写不敏感.
3. opt_name
4. opt_name=value
在option文件中,你可以在=前后加空格,而在命令行中是不行的.
value可以使用单引号或者双引号括起来,比如value中有#符号.
----------首尾的空格自动删除-------
可以分别用转义符+缩写字母 代表:
\b -->backspace ; \t -->tab ; \n=newline;\r=carriage return,\\=backslash(\); \s=space.
a backslash not followed by a valid escape sequence character remain unchanged.
也就是说\后面只要不跟那些valid escape sequence charater比如s,n等,还表示自身\
option文件中escape sequence规则和sql statement中的稍有不同.
在后者,如果x 不是valid escape sequence 字符,\x=x而不是\x.
iF an option group name is the same as a program name, options in the group apply specifically to that program.
如果option group名和程序名相同,group会自动应用于程序.比如[mysqld] ,[mysql] groups 分别apply to mysqld server and the mysql client程序.
[client] option group is read by all client programs provided in MySQL distributions (but ont by mysqld).
The [client] group enables you to specify options that apply to all clients.
For example, [client] is the appropriate group to use to specify the password for connecting to the server.
Be sure not to put an option in the [client] gourp unless it is recognized by all client programs that you use.
Programs that do not understand the option quit after displaying an error message if you try to run them.
不是说group后的option在下一个group name之前生效吗?
typical global option file:
typical user option file:
特定版本的MySQL,组名后缀"-版本号"
还可以通过!include 来包含其他目录的option文件
.!include /home/mydir/myopt.cnf
或者只指定路径:
!includedir /home/mydir
On Windows, this directive checks for files with the .ini
or .cnf
extension.