MySQL配置文件加載順序

有一次在幫助朋友排查mysql問題時,想看一下mysql數據庫的參數配置,就去/etc/下去找my.cnf文件,結果沒有找到這個文件,當時就有點懵,mysql配置哪兒去了,我該怎麼找,因而就是嘗試用下面命令去找mysql

/u02/mysql/bin/mysql --socket=/u02/run/3308/mysql.sock -uroot -proot -e "show variables"|grep -i ".cnf"複製代碼

結果發現配置文件沒有在參數裏,後來一想,這個方式確定是行不通,由於my.cnf裏沒有添加參數文件參數,用show variables,天然就沒法獲取當前mysql數據庫加載配置文件位置了。sql

那怎麼才能獲取mysql數據庫加載配置文件呢,下面給你們介紹mysql加載配置文件的順序,以及怎麼去查找數據庫

方法1:若是mysql啓動時指定了配置文件,則使用如下方法架構

[root@ ~]# ps -ef|grep -i mysql
root     24858 24788  0 17:57 pts/2    00:00:00 grep --color=auto -i mysql
root     29169     1  0 Sep24 ?        00:00:00 /bin/sh /u02/mysql/bin/mysqld_safe --defaults-file=/u02/conf/my3308.cnf
mysql    30250 29169  0 Sep24 ?        02:27:42 /u02/mysql/bin/mysqld --defaults-file=/u02/conf/my3308.cnf --basedir=/u02/mysql --datadir=/u02/data/3308 --plugin-dir=/u02/mysql/lib/plugin --user=mysql --log-error=/u02/log/3308/error.log --open-files-limit=65535 --pid-file=/u02/run/3308/mysqld.pid --socket=/u02/run/3308/mysql.sock --port=3308
root     30699     1  0 Sep24 ?        00:00:00 /bin/sh -c /usr/local/percona/qan-agent/bin/percona-qan-agent >> /var/log/pmm-mysql-queries-0.log 2>&1複製代碼

上述結果中的--defaults-file=/u02/conf/my3308.cnf就是配置文件位置運維

方法2:若是mysql啓動時沒有指定配置,這使用如下方法獲取配置文件位置socket

[root@]# /u02/mysql/bin/mysql --help|grep -i "my.cnf"
                      order of preference, my.cnf, $MYSQL_TCP_PORT, built-in
/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf
複製代碼

加載順序爲/etc/mysql/my.cnf /etc/my.cnf ~/.my.cnfui

若是以上方式都沒有找到配置文件,則mysql啓動時使用默認參數配置spa

喜歡的同窗能夠關注個人公衆號(db_arch)(Mysql數據庫運維與架構設計)架構設計

相關文章
相關標籤/搜索