码迷,mamicode.com
首页 > 数据库 > 详细

MySQL配置文件读取顺序

时间:2014-07-22 18:24:02      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:mysql   配置文件   

启动进程的参数

    The MySQL server maintains many system variables that indicate how it is configured. Each system variable has a default value. System variables can be set at server startup using options on the command line or in an option file. Most of them can bechanged dynamically while the server is running by means of the SET statement,which enables you to modify operation of the server without having to stop and restart it. You can refer to system variable values in expressions.

 

在启动MySQL 时,我们可以手工的在命令后面指定相关的参数:

# mysqld_safe --basedir=/usr/local/mysql --datadir=/mydata/data --user=mysql --pid-file=/var/lib/mysql/mysql.pid --socket=/var/lib/mysql/mysql.sock --port=3306

 

这里是我们的默认的一个参数值,我们可以通过如下命令来查看MySQL的默认参数的具体值:

(1)To see the values that a serverwill use based on its compiled-in defaults and any option files that it reads,use this command:

# mysqld --verbose --help

(2)To see the values that a serverwill use based on its compiled-in defaults, ignoring the settings in any optionfiles, use this command:

# mysqld --no-defaults --verbose --help

      

如果每次启动都手工的指定参数比较麻烦,我们可以把相关的参数配置到参数文件里,在MySQL启动时会读取这些文件,参数文件的位置:

On Unix, Linux and Mac OS X, MySQL programsread startup options from the following files, in the specified order (topitems are used first).

bubuko.com,布布扣


    注意上表中参数文件的顺序,MySQL 会按照从上往下的顺序优先使用上面的参数文件。

 

  • ~          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=<配置文件的绝对路径>参数,这时只会使用这个参数指定的配置文件。


本文出自 “Share your knowledge” 博客,请务必保留此出处http://skypegnu1.blog.51cto.com/8991766/1441266

MySQL配置文件读取顺序

标签:mysql   配置文件   

原文地址:http://skypegnu1.blog.51cto.com/8991766/1441266

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!