您的位置:首页 > 博客中心 > 数据库 >

MySQL配置文件读取顺序

时间:2022-03-10 18:08

  • ~          represents the current user‘s home directory (the value of $HOME).

  • SYSCONFDIR representsthe directory specified with the SYSCONFDIR option to CMake when MySQL wasbuilt. By default, this is the etc directory located under the compiled-ininstallation directory.

  • MYSQL_HOME is an environment variable containing the path to the directory in which theserver-specific my.cnf file resides. If MYSQL_HOME is not set and you start theserver using the mysqld_safe program, mysqld_safe attempts to set MYSQL_HOME asfollows:

  • (1)Let BASEDIR and DATADIR representthe path names of the MySQL base directory and data directory, respectively.

    (2)If there is a my.cnf file in DATADIR but not in BASEDIR, mysqld_safe sets MYSQL_HOME to DATADIR.

    (3)Otherwise, if MYSQL_HOME is not setand there is no my.cnf file in DATADIR, mysqld_safe sets MYSQL_HOME to BASEDIR.

     

    In MySQL 5.5,use of DATADIR as the location for my.cnf is deprecated.

           --在MySQL 5.5中,my.cnf 文件已经不放在DATADIR目录下。

     

        Typically, DATADIR is /usr/local/mysql/data for a binary installation or /usr/local/var for a source installation. Note that this is the data directory location that wasspecified at configuration time, not the one specified with the --datadir optionwhen mysqld starts. Use of --datadir at runtime has no effect on where theserver looks for option files, because it looks for them before processing anyoptions.


        假设4个配置文件都存在,同时使用--defaults-extra-file指定了参数文件,如果这时有一个 "参数变量"在5个配置文件中都出现了,那么后面的配置文件中的参数变量值会覆盖前面配置文件中的参数变量值,就是说会使用~/.my.cnf中设置的值。

        也就是说,当有多个配置文件同时存在时,MySQL会以最后一个配置中的参数为准。越靠后读取,那么作用的优先级越高,这是linux的通用规则。

    *****注意*****

       如果使用./bin/mysqld_safe 守护进程启动mysql数据库时,使用了 --defaults-file=<配置文件的绝对路径>参数,这时只会使用这个参数指定的配置文件。


    本文出自 “” 博客,请务必保留此出处

    热门排行

    今日推荐

    热门手游