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