File Name Purpose /etc/my.cnf Global options /etc/mysql/my.cnf Global options SYSCONFDIR/my.cnf Global options $MYSQL_HOME/my.cnf Server-specific options defaults-extra-file The file specified with --defaults-extra-file=path, if any ~/.my.cnf User-specific options ~/.mylogin.cnf Login path options
實驗: /etc/my.cnf [mysqld] long_query_time = 15 slow_query_log = on autocommit = off
/etc/mysql/my.cnf [mysqld] long_query_time = 12 slow_query_log = on
查詢:
mysql> show variables like 'autocommit'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | autocommit | OFF | +---------------+-------+ 1 row in set (0.00 sec)
mysql> show variables like 'long_query_time'; +-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 12.000000 | +-----------------+-----------+ 1 row in set (0.01 sec)
mysql> show variables like 'autocommit'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | autocommit | ON | +---------------+-------+ 1 row in set (0.00 sec)
mysql> show variables like 'long_query_time'; +-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 12.000000 | +-----------------+-----------+ 1 row in set (0.01 sec)
此時只用了/etc/mysql/my.cnf。
場景二: Global options與User-specific options同時存在 即/etc/my.cnf與~/.my.cnf同時存在
實驗: 同樣先刪除其他配置文件,確保只剩如下兩個位置:
/etc/my.cnf [mysqld] long_query_time = 15 slow_query_log = on autocommit = off
~/.my.cnf [mysqld] long_query_time = 12 slow_query_log = on
編輯好后保存退出
查詢:
mysql> show variables like 'autocommit'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | autocommit | OFF | +---------------+-------+ 1 row in set (0.00 sec)
mysql> show variables like 'long_query_time'; +-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 12.000000 | +-----------------+-----------+ 1 row in set (0.01 sec)
autocommit默認是on long_query_time默認是10
說明/etc/my.cnf已經生效 autocommit = off 雖然有設置 long_query_time = 15