查看當前mysql使用的配置文件是哪一個

my.cnf是mysql啓動時加載的配置文件,通常會放在mysql的安裝目錄中,用戶也能夠放在其餘目錄加載。
安裝mysql後,系統中會有多個my.cnf文件,有些是用於測試的。
使用locate my.cnf命令能夠列出全部的my.cnf文件
注意:執行locate以前先執行updatedb,更新系統庫。默認系統時凌晨更新庫,若是你上午8點添加配置文件,執行locate可能就顯示出來node

命令
locate my.cnfmysql

 

輸出linux

/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文件。sql

一、查看是否使用了指定目錄的my.cnf
啓動mysql後,咱們查看mysql的進程,看看是否有設置使用指定目錄的my.cnf文件,若是有則表示mysql啓動時是加載了這個配置文件。bash

命令
ps aux|grep mysql|grep 'my.cnf'socket

[root@linux-node1 ~]# ps aux |grep mysql
root       2684  0.0  0.0 106100   736 ?        S    Mar30   0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql 
--socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql      2831  0.2  2.2 2232232 45212 ?       Sl   Mar30  33:28 /usr/libexec/mysqld --basedir=/usr 
--datadir=/var/lib/mysql --user=mysql --log-error=/var/lib/mysql/linux-node1.example.com.err 
--pid-file=/var/run/mysqld/mysqd.pid --socket=/var/lib/mysql/mysql.sock --port=3306
root      95228  0.0  0.0 103256   944 pts/0    S+   13:00   0:00 grep --colour=auto mysql
[root@linux-node1 ~]# ps aux |grep mysql | grep 'my.cnf'
[root@linux-node1 ~]# 

  

若是上面的命令沒有輸出,表示沒有設置使用指定目錄的my.cnf。測試

二、查看mysql默認讀取my.cnf的目錄
若是沒有設置使用指定目錄的my.cnf,mysql啓動時會讀取安裝目錄根目錄及默認目錄下的my.cnf文件。
查看mysql啓動時讀取配置文件的默認目錄ui

 

命令
mysql --help|grep 'my.cnf'blog

[root@linux-node1 ~]# mysql --help | grep 'my.cnf'
                      order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf 
[root@linux-node1 ~]# 

這些就是mysql默認會搜尋my.cnf的目錄,順序排前的優先。進程

三、啓動時沒有使用配置文件若是沒有設置使用指定目錄my.cnf文件及默認讀取目錄沒有my.cnf文件,表示mysql啓動時並無加載配置文件,而是使用默認配置。須要修改配置,能夠在mysql默認讀取的目錄中,建立一個my.cnf文件(例如:/etc/my.cnf),把須要修改的配置內容寫入,重啓mysql後便可生效。

相關文章
相關標籤/搜索