my.cnf is a configuration file that is loaded at MySQL startup and is typically placed in the MySQL installation directory and can be loaded by users in other directories.
After installing MySQL, there will be multiple MY.CNF files in the system, some of which are for testing.
Use the locate my.cnf command to list all my.cnf files
Command
Locate MY.CNF
Output
1234567891011 |
/usr/
local
/Cellar/mysql/5.6.24/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/include/default_my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/federated/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/ndb/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/ndb_big/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/ndb_binlog/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/ndb_rpl/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/ndb_team/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/rpl/extension/bhs/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/rpl/my.cnf
/usr/
local
/Cellar/mysql/5.6.24/mysql-test/suite/rpl_ndb/my.cnf
|
When we need to modify the configuration file, we need to find out which my.cnf file was loaded when MySQL started.
1. See if the my.cnf of the specified directory is used
After starting MySQL, we look at the MySQL process to see if there is a my.cnf file set up using the specified directory, and if so, this is the configuration file that was loaded when MySQL was started.
Command
PS aux|grep mysql|grep ' my.cnf '
Output
12 |
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
|
You can see that/usr/local/cellar/mysql/5.6.24/my.cnf is the MySQL boot loaded configuration file.
If the above command has no output, MY.CNF is not set using the specified directory.
2. View MySQL default read my.cnf directory
If you do not set a My.cnf,mysql startup with the specified directory, the root directory of the installation directory and the my.cnf file under the default directory will be read.
View the default directory for reading the configuration file when MySQL starts
Command
MySQL--help|grep ' my.cnf '
Output
?
123 |
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 |
These are the MySQL default will search my.cnf directory, the order of precedence before the queue.
3. No configuration file used at startup
If no my.cnf file is set using the specified directory my.cnf file and the default read directory, it means that the configuration file is not loaded when MySQL starts, but instead uses the default configuration.
To modify the configuration, you can create a my.cnf file (for example:/ETC/MY.CNF) in the directory that the MySQL default reads, write the configuration that needs to be modified, and then take effect after restarting MySQL.
MySQL View the currently used configuration file My.cnf method