MySQL的配置文件在哪里? - 红帽Linux服务器

43

在红帽Linux系统上,MySQL配置文件的默认位置是什么?

8个回答

58

刚发现,它是 /etc/my.cnf


48

您想要的信息可以通过运行以下代码找到:

mysql --help
或者
mysqld --help --verbose

我尝试了这个:

    mysql --help | grep Default -A 1

输出结果为:

                      (Defaults to on; use --skip-auto-rehash to disable.)
  -A, --no-auto-rehash 
--
                      (Defaults to on; use --skip-line-numbers to disable.)
  -L, --skip-line-numbers 
--
                      (Defaults to on; use --skip-column-names to disable.)
  -N, --skip-column-names 
--
                      (Defaults to on; use --skip-reconnect to disable.)
  -s, --silent        Be more silent. Print results with a tab as separator,
--
  --default-auth=name Default authentication client-side plugin to use.
  --binary-mode       By default, ASCII '\0' is disallowed and '\r\n' is
--
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf 

对我来说,使用/usr/libexec/mysqld --help --verbose而不是mysqld --help --verbose有效。 - Andron
2
@Andron 如果可执行守护程序的路径不在环境变量PATH中,您将需要指定守护程序可执行文件的绝对路径。 - ThinkingMonkey

21
该配置文件位于/etc/mysql/my.cnf

3
在基于Debian的发行版中,这是默认设置,但在RedHat上无效。 - Kaii

8

所有人都是好的候选者:

/etc/my.cnf
/etc/mysql/my.cnf
/var/lib/mysql/my.cnf
...

在许多情况下,您可以使用ps命令来检查系统进程列表:

server ~ # ps ax | grep '[m]ysqld'

输出

10801 ?        Ssl    0:27 /usr/sbin/mysqld --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/lib/mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock

或者

which mysqld
/usr/sbin/mysqld

那么

/usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"

/etc/mysql/my.cnf ~/.my.cnf /usr/etc/my.cnf

5

在RH系统上,MySQL的配置文件默认位于/etc/my.cnf。


5

默认选项按照给定顺序从以下文件中读取:

/etc/mysql/my.cnf 
/etc/my.cnf 
~/.my.cnf 

3
在 Docker 容器(基于 CentOS 的镜像)中,MySQL 配置文件位于 /etc/mysql/my.cnf。

1

从 '/etc/mysql/my.cnf' 的头部:

MariaDB programs look for option files in a set of
locations which depend on the deployment platform.
[...] For information about these locations, do:
'my_print_defaults --help' and see what is printed under
"Default options are read from the following files in the given order:"
More information at: http://dev.mysql.com/doc/mysql/en/option-files.html

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接