Using Option Files --MySQL Concept

本文详细介绍了MySQL程序如何从选项文件读取启动参数,包括预配置的选项文件、登录路径选项文件以及如何在不同操作系统环境下配置这些文件。重点讨论了如何通过命令行参数检查程序是否读取选项文件,并提供了在Windows和Unix/Linux/OSX系统中查找和使用选项文件的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值