摘要:本文主要了解了在Linux环境下安装MySQL后的配置文件的位置,以及如何建立配置文件。mysql
经过which命令查询mysqld的路径:sql
1 [root@localhost ~]# which mysqld 2 /usr/sbin/mysqld 3 [root@localhost ~]#
经过帮助文件找到配置文件的加载路径:spa
1 [root@localhost ~]# /usr/sbin/mysqld --help --verbose | grep -A 1 'Default options' 2 2019-11-18 19:13:20 0 [Note] /usr/sbin/mysqld (mysqld 5.6.45) starting as process 1802 ... 3 2019-11-18 19:13:20 1802 [Note] Plugin 'FEDERATED' is disabled. 4 Default options are read from the following files in the given order: 5 /etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf 6 2019-11-18 19:13:20 1802 [Note] Binlog end 7 2019-11-18 19:13:20 1802 [Note] Shutting down plugin 'MyISAM' 8 2019-11-18 19:13:20 1802 [Note] Shutting down plugin 'CSV' 9 [root@localhost ~]#
这个帮助文件显示的内容说明在加载配置文件时,首先读取的是 /etc/my.cnf 文件,若是文件不存在则继续读取 /etc/mysql/my.cnf 文件,如若还不存在便会去读 /usr/etc/my.cnf 文件,若是以前的文件都不存在,则最后尝试读取 ~/.my.cnf 文件。code
使用whereis命令查询MySQL的配置文件:blog
1 [root@localhost ~]# whereis my.cnf 2 my: /etc/my.cnf 3 [root@localhost ~]#
结果显示了配置文件的位置,若是没有找到,则须要找一个默认的配置文件复制一下。io
若是没有发现配置文件,则寻找mysql的位置:入门
1 [root@localhost ~]# whereis mysql 2 mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz 3 [root@localhost ~]#
而后进入 /usr/share/mysql 文件夹:class
1 [root@localhost ~]# cd /usr/share/mysql 2 [root@localhost mysql]#
找到默认的配置文件:配置
1 [root@localhost mysql]# find ./ -name '*.cnf' 2 ./my-default.cnf 3 [root@localhost mysql]#
复制到默认的目录下并更名:file
1 [root@localhost mysql]# cp my-default.cnf /etc/my.cnf 2 [root@localhost mysql]#
配置文件就生成完毕了。