my.cnf是mysql啓動時加載的配置文件,通常會放在mysql的安裝目錄中,用戶也能夠放在其餘目錄加載。mysql
安裝mysql後,系統中會有多個my.cnf文件,有些是用於測試的。sql
使用locate my.cnf命令能夠列出全部的my.cnf文件測試
命令
ui
locate my.cnfspa
輸出
code
1
2
3
4
5
6
7
8
9
10
11
|
/usr/
local
/Cellar/mysql/5.6.24/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/include/default_my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/federated/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/ndb/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/ndb_big/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/ndb_binlog/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/ndb_rpl/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/ndb_team/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/rpl/extension/bhs/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/rpl/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/rpl_ndb/my.cnf
|
當咱們須要修改配置文件時,須要找到mysql啓動時是加載了哪一個my.cnf文件。進程
一、查看是否使用了指定目錄的my.cnfip
啓動mysql後,咱們查看mysql的進程,看看是否有設置使用指定目錄的my.cnf文件,若是有則表示mysql啓動時是加載了這個配置文件。ci
命令
it
ps aux|grep mysql|grep 'my.cnf'
輸出
1
2
|
fdipzone 25174 0.0 0.0 3087244 600 ?? S 4:12下午 0:01.14 /usr/
local
/Cellar/mysql/5.6.24/bin/mysqld
--defaults-file=/usr/local/Cellar/mysql/5.6.24/my.cnf --basedir=/usr/local/Cellar/mysql/5.6.24 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql/5.6.24/lib/plugin --bind-address=127.0.0.1 --log-error=/usr/local/var/mysql/TerrydeMacBook-Air.local.err --pid-file=/usr/local/var/mysql/TerrydeMacBook-Air.local.pid
fdipzone 25064 0.0 0.0 2452824 4 ?? S 4:12下午 0:00.03 /bin/sh /usr/
local
/opt/mysql/bin/mysqld_safe
--defaults-file=/usr/local/Cellar/mysql/5.6.24/my.cnf --bind-address=127.0.0.1 --datadir=/usr/local/var/mysql
|
能夠看到/usr/local/Cellar/mysql/5.6.24/my.cnf就是mysql啓動加載的配置文件。
若是上面的命令沒有輸出,表示沒有設置使用指定目錄的my.cnf。
二、查看mysql默認讀取my.cnf的目錄
若是沒有設置使用指定目錄的my.cnf,mysql啓動時會讀取安裝目錄根目錄及默認目錄下的my.cnf文件。
查看mysql啓動時讀取配置文件的默認目錄
命令
mysql --help|grep 'my.cnf'
輸出
1
2
3
|
order
of
preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/
local
/etc/my.cnf ~/.my.cnf
/etc/my.cnf, /etc/mysql/my.cnf, /usr/
local
/etc/my.cnf, ~/.my.cnf
|
這些就是mysql默認會搜尋my.cnf的目錄,順序排前的優先。
三、啓動時沒有使用配置文件
若是沒有設置使用指定目錄my.cnf文件及默認讀取目錄沒有my.cnf文件,表示mysql啓動時並無加載配置文件,而是使用默認配置。
須要修改配置,能夠在mysql默認讀取的目錄中,建立一個my.cnf文件(例如:/etc/my.cnf),把須要修改的配置內容寫入,重啓mysql後便可生效。