my.cnf是mysql启动时加载的配置文件,通常会放在mysql的安装目录中,用户也能够放在其余目录加载。
安装mysql后,系统中会有多个my.cnf文件,有些是用于测试的。
使用locate my.cnf命令能够列出全部的my.cnf文件
注意:执行locate以前先执行updatedb,更新系统库。默认系统时凌晨更新库,若是你上午8点添加配置文件,执行locate可能就显示出来node
命令
locate my.cnfmysql
输出linux
/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
当咱们须要修改配置文件时,须要找到mysql启动时是加载了哪一个my.cnf文件。sql
一、查看是否使用了指定目录的my.cnf
启动mysql后,咱们查看mysql的进程,看看是否有设置使用指定目录的my.cnf文件,若是有则表示mysql启动时是加载了这个配置文件。bash
命令
ps aux|grep mysql|grep 'my.cnf'socket
[root@linux-node1 ~]# ps aux |grep mysql root 2684 0.0 0.0 106100 736 ? S Mar30 0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql mysql 2831 0.2 2.2 2232232 45212 ? Sl Mar30 33:28 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/lib/mysql/linux-node1.example.com.err --pid-file=/var/run/mysqld/mysqd.pid --socket=/var/lib/mysql/mysql.sock --port=3306 root 95228 0.0 0.0 103256 944 pts/0 S+ 13:00 0:00 grep --colour=auto mysql [root@linux-node1 ~]# ps aux |grep mysql | grep 'my.cnf' [root@linux-node1 ~]#
若是上面的命令没有输出,表示没有设置使用指定目录的my.cnf。测试
二、查看mysql默认读取my.cnf的目录
若是没有设置使用指定目录的my.cnf,mysql启动时会读取安装目录根目录及默认目录下的my.cnf文件。
查看mysql启动时读取配置文件的默认目录ui
命令
mysql --help|grep 'my.cnf'blog
[root@linux-node1 ~]# mysql --help | grep 'my.cnf' order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf [root@linux-node1 ~]#
这些就是mysql默认会搜寻my.cnf的目录,顺序排前的优先。进程
三、启动时没有使用配置文件若是没有设置使用指定目录my.cnf文件及默认读取目录没有my.cnf文件,表示mysql启动时并无加载配置文件,而是使用默认配置。须要修改配置,能够在mysql默认读取的目录中,建立一个my.cnf文件(例如:/etc/my.cnf),把须要修改的配置内容写入,重启mysql后便可生效。