MySQL檢視當前使用的配置檔案my.cnf的方法

lhrbest發表於2017-03-22

MySQL檢視當前使用的配置檔案my.cnf的方法


MySQL例項啟動時,會先讀取配置引數檔案my.cnfmy.cnf一般會放在MySQL的安裝目錄中,使用者也可以放在其他目錄載入。安裝MySQL後,系統中會有多個my.cnf檔案,有些是用於測試的。使用“locate my.cnf“find / -name my.cnf”命令可以列出所有的my.cnf檔案。

有時候,DBA發現雖然嘗試修改了配置檔案的一些變數,但是並沒有生效,這其實是因為修改的檔案並非MySQL伺服器讀取的配置檔案。MySQL伺服器讀取的配置檔案及路徑預設為:

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

如果不清楚MySQL當前使用的配置檔案路徑,那麼可以安裝如下步驟來檢視:

(一)檢視是否使用了指定目錄的my.cnf檔案

在啟動MySQL後,可以通過檢視MySQL的程式,看看是否有設定使用指定目錄的my.cnf檔案,如果有則表示MySQL啟動時是載入了這個配置檔案。

命令:ps -ef|grep mysql|grep 'my.cnf'

輸出:

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.cnfMySQL啟動時會讀取安裝目錄根目錄及預設目錄下的my.cnf檔案。

命令:mysql --help|grep 'my.cnf'  mysqld --verbose --help |grep -A 1 'Default options'

輸出:

                      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後即可生效。




[root@rhel6lhr mysql]# find / -name my.cnf

/usr/my.cnf

/usr/share/mysql-test/suite/ndb_team/my.cnf

/usr/share/mysql-test/suite/federated/my.cnf

/usr/share/mysql-test/suite/ndb_big/my.cnf

/usr/share/mysql-test/suite/rpl_ndb/my.cnf

/usr/share/mysql-test/suite/rpl/my.cnf

/usr/share/mysql-test/suite/rpl/extension/bhs/my.cnf

/usr/share/mysql-test/suite/ndb_rpl/my.cnf

/usr/share/mysql-test/suite/ndb/my.cnf

/usr/share/mysql-test/suite/ndb_binlog/my.cnf

/var/lib/mysql/my.cnf

/etc/my.cnf

[root@rhel6lhr mysql]#

[root@rhel6lhr mysql]# locate my.cnf

/etc/my.cnf

/etc/my.cnf.d

/etc/my.cnf.rpmnew

/etc/my.cnf.rpmsave

/usr/my.cnf

/usr/share/mysql-test/include/default_my.cnf

/usr/share/mysql-test/suite/federated/my.cnf

/usr/share/mysql-test/suite/ndb/my.cnf

/usr/share/mysql-test/suite/ndb_big/my.cnf

/usr/share/mysql-test/suite/ndb_binlog/my.cnf

/usr/share/mysql-test/suite/ndb_rpl/my.cnf

/usr/share/mysql-test/suite/ndb_team/my.cnf

/usr/share/mysql-test/suite/rpl/my.cnf

/usr/share/mysql-test/suite/rpl/extension/bhs/my.cnf

/usr/share/mysql-test/suite/rpl_ndb/my.cnf

/var/lib/mysql/.my.cnf.swp

/var/lib/mysql/my.cnf

/var/lib/mysql/my.cnf_bk

[root@rhel6lhr mysql]#

[root@rhel6lhr mysql]# mysql --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

[root@rhel6lhr mysql]#

[root@rhel6lhr mysql]# which mysqld

/usr/sbin/mysqld

[root@rhel6lhr mysql]# /usr/sbin/mysqld --verbose --help |grep -A 1 'Default options'

2017-03-22 19:24:11 20934 [Warning] No argument was provided to --log-bin, and --log-bin-index was not used; so replication may break when this MySQL server acts as a master and has his hostname changed!! Please use '--log-bin=rhel6lhr-bin' to avoid this problem.

2017-03-22 19:24:11 20934 [Note] Plugin 'FEDERATED' is disabled.

Default options are read from the following files in the given order:

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

2017-03-22 19:24:11 20934 [Note] Binlog end

2017-03-22 19:24:11 20934 [Note] Shutting down plugin 'CSV'

2017-03-22 19:24:11 20934 [Note] Shutting down plugin 'MyISAM'

[root@rhel6lhr mysql]#  whereis my.cnf

my: /etc/my.cnf

[root@rhel6lhr mysql]#






About Me

.............................................................................................................................................

● 本文作者:小麥苗,只專注於資料庫的技術,更注重技術的運用

● 本文在itpub(http://blog.itpub.net/26736162/abstract/1/)、部落格園(http://www.cnblogs.com/lhrbest)和個人微信公眾號(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/

● 本文部落格園地址:http://www.cnblogs.com/lhrbest

● 本文pdf版、個人簡介及小麥苗雲盤地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 資料庫筆試面試題庫及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● DBA寶典今日頭條號地址:http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826

.............................................................................................................................................

● QQ群:230161599     微信群:私聊

● 聯絡我請加QQ好友(646634621),註明新增緣由

● 於 2017-07-01 09:00 ~ 2017-07-31 22:00 在魔都完成

● 文章內容來源於小麥苗的學習筆記,部分整理自網路,若有侵權或不當之處還請諒解

● 版權所有,歡迎分享本文,轉載請保留出處

.............................................................................................................................................

小麥苗的微店https://weidian.com/s/793741433?wfr=c&ifr=shopdetail

小麥苗出版的資料庫類叢書http://blog.itpub.net/26736162/viewspace-2142121/

.............................................................................................................................................

使用微信客戶端掃描下面的二維碼來關注小麥苗的微信公眾號(xiaomaimiaolhr)及QQ群(DBA寶典),學習最實用的資料庫技術。

   小麥苗的微信公眾號          小麥苗的QQ群             小麥苗的微店

.............................................................................................................................................

MySQL檢視當前使用的配置檔案my.cnf的方法
DBA筆試面試講解
歡迎與我聯絡



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-2135880/,如需轉載,請註明出處,否則將追究法律責任。

相關文章