Mysql配置檔案讀取順序

2021-08-20 04:57:14 字數 2338 閱讀 4390

一、mysql讀取配置檔案的順序

讀取順序:/etc/my.cnf > /etc/mysql/my.cnf > /usr/etc/my.cnf > ~/.my.cnf

命令驗證:

[root@mysql ~]# mysql --verbose --help | grep my.cnf

order of preference, my.cnf, $mysql_tcp_port,

/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

二、mysql啟動方式

mysql的啟動方式通常分成三種:mysqld、mysqld_safe、mysqld_multi(主要用於多例項啟動)

三種方式的關係:

首先當我們使用service mysqld start或者/etc/init.d/mysqld start這樣的方式啟動的時候,其實是使用了mysql.server這個指令碼,這個指令碼缺省會呼叫mysqld_safe來啟動mysqld,所以通常我們啟動mysql之後檢視程序的時候會發現有mysqld和mysqld_safe這兩個程序存在。這兩種通常都是單例項的啟動方式,當然也可以使用mysqld來啟動多例項的。而mysqld_multi用來啟動多例項,也是通過先呼叫mysqld_safe和mysqld來啟動mysql的。

三、mysql啟動原理

預設的mysql的服務啟動程式是mysql.server,mysql.server程式主要是會用到兩個程式和乙個函式,分別是my_print_defaults、myslqd_safe和parse_server_arguments

1、my_print_defaults:讀取my.cnf配置檔案,輸出引數傳遞給parse_server_arguments,該程式唯讀my.cnf中[mysqld]中的引數。

2、parse_server_arguments:該函式處理my_print_defaults傳遞過來的引數賦值給--basedir、--datadir、--pid-file、--server-startup-timeout

3、myslqd_safe:mysqld_safe程式呼叫mysqld程式來啟動mysql服務,[mysqld_safe]會覆蓋mysqld部分中的引數

4、mysqld_multi會讀取配置檔案中的[mysqld_muti],[mysqldn]下面的引數,n需要時乙個整數,建議用埠號表示,該部分的配置會覆蓋[mysqld]部分中的配置

5、在mysqld程序掛掉的時候,mysqld_safe程序會監測到並重新將mysqld啟動起來。

on unix, linux and mac os x, mysql programs read startup options from the following files, in the specified order (top items are used first).

file name

purpose

/etc/my.cnfglobal options

/etc/mysql/my.cnfglobal options

sysconfdir/my.cnf

global options

$mysql_home/my.cnfserver-specific options

defaults-extra-filethe file specified with--defaults-extra-file=path

, if any

~/.my.cnfuser-specific options

讀取順序為:

/etc/my.cnf

basedir/my.cnf

datadir/my.cnf

--defaults-extra-file    #在讀取全域性配置檔案之後,讀取使用者配置檔案(~/.my.cnf)之前,讀取extra指定的引數檔案

~/.my.cnf      #家目錄下面的隱藏檔案,my.cnf前面的點,說明my.cnf是隱藏檔案   

假設4個配置檔案都存在,同時使用--defaults-extra-file指定了引數檔案,如果這時有乙個 "引數變數"在5個配置檔案中都出現了,那麼後面的配置檔案中的引數變數值 會 覆蓋 前面配置檔案中的引數變數值,就是說會使用~/.my.cnf中設定的值。

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

如果使用./bin/mysqld_safe 守護程序啟動mysql資料庫時,使用了 --defaults-file=《配置檔案的絕對路徑》引數,這時只會使用這個引數指定的配置檔案。

mysql配置檔案讀取順序

on unix,linux and mac os x,mysql programs read startup options from the following files,in the specified order top items are used first file name purp...

MySQL讀取配置檔案的順序 啟動方式 啟動原理

一 mysql讀取配置檔案的順序 讀取順序 etc my.cnf etc mysql my.cnf usr etc my.cnf my.cnf 命令驗證 root mysql mysql verbose help grep my.cnf order of preference,my.cnf,mysq...

MySQL讀取配置檔案的順序 啟動方式 啟動原理

一 mysql讀取配置檔案的順序 讀取順序 etc my.cnf etc mysql my.cnf usr etc my.cnf my.cnf 命令驗證 root mysql mysql verbose help grep my.cnf order of preference,my.cnf,mysq...