(1)關於配置文件路徑
有時候,我發現雖然嘗試修改了配置文件的一些變量,但是並沒有生效。后來才發現原來是因為修改的文件並非MySQL服務器讀取的配置文件。
如果不清楚MySQL當前使用的配置文件路徑,可以嘗試這樣查看:
[mysql@linuxtest ~]$ mysqld --verbose --help|grep -A 1 'Default options'
或者是執行:
[mysql@linuxtest ~]$ mysql --verbose --help|grep -A 1 'Default options'
[mysql@linuxtest ~]$ mysqld --verbose --help|grep -A 1 'Default options' 2015-12-01 17:23:56 0 [Note] mysqld (mysqld 5.6.27-75.0-log) starting as process 6858 ... 2015-12-01 17:23:56 6858 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 10005) 2015-12-01 17:23:56 6858 [Warning] Buffered warning: Changed limits: max_connections: 214 (requested 2000) 2015-12-01 17:23:56 6858 [Warning] Buffered warning: Changed limits: table_open_cache: 400 (requested 2000) 2015-12-01 17:23:56 6858 [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 2015-12-01 17:23:56 6858 [Note] Binlog end 2015-12-01 17:23:56 6858 [Note] Shutting down plugin 'CSV' 2015-12-01 17:23:56 6858 [Note] Shutting down plugin 'MyISAM'
[mysql@linuxtest ~]$ mysql --verbose --help|grep -A 1 'Default options' 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
從上圖可以看出, 服務器首先會讀取/etc/my.cnf文件,如果發現該文件不存在,再依次嘗試從后面的幾個路徑進行讀取。
(2)關於配置文件配置項分段
配置文件my.cnf通常會分成好幾部分,如[client],[mysqld], [mysql]等等。MySQL程序通常是讀取與它同名的分段部分,例如服務器mysqld通常讀取[mysqld]分段下的相關配置項。如果配置項位置不正確,該配置是不會生效的。詳細文檔我覺得可以參考這篇文章:http://www.blogjava.net/hunter129/archive/2009/01/18/251744.html。
(3)關於全局變量
另外,如果想查看MySQL的一些全局變量設置,在非登錄並有權限情況下可以這樣查看: mysqladmin variables -p,
這個操作也就相當於登錄時使用命令 show global variables;