標籤: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).
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/40/03/wKioL1PN3-6ScVkDAAD1Wg0zy8E567.jpg" title="9.png" alt="wKioL1PN3-6ScVkDAAD1Wg0zy8E567.jpg" />
注意上表中參數檔案的順序,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設定檔讀取順序