是否有一个MySQL命令来定位my.cnf配置文件,类似于PHP的phpinfo()定位它的PHP .ini?
当前回答
所有很棒的建议,在我的情况下,我没有在任何这些位置找到它,但在/usr/share/mysql,我有一个RHEL虚拟机,我安装了mysql5.5
其他回答
你可以用find命令找到my.cnf或任何其他文件:
find / -name my.cnf (or any other file name)
Find是一条命令 /(斜杠)为路径 My.cnf是一个文件名
对于Ubuntu 20.04.4 LTS上的MariaDB 10.5 (Focal Fossa):
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read.
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
你可以使用:
locate my.cnf
whereis my.cnf
find . -name my.cnf
mysql --help | grep /my.cnf | xargs ls
会告诉你my.cnf在Mac/Linux上的位置吗
ls: cannot access '/etc/my.cnf': No such file or directory
ls: cannot access '~/.my.cnf': No such file or directory
/etc/mysql/my.cnf
在本例中,它在/etc/mysql/my.cnf中
ls: /etc/my.cnf: No such file or directory
ls: /etc/mysql/my.cnf: No such file or directory
ls: ~/.my.cnf: No such file or directory
/usr/local/etc/my.cnf
在本例中,它位于/usr/local/etc/my.cnf
请注意,尽管mariadDB从其他答案中列出的各种my.cnf文件加载配置详细信息,但它也可以从其他具有不同名称的文件加载配置详细信息。
这意味着如果您对my.cnf文件中的一个进行了更改,它可能会被另一个具有不同名称的文件覆盖。要使更改生效,您需要在正确的(最后加载的)配置文件中更改它-或者,可能在所有配置文件中更改它。
那么如何找到所有可能加载的配置文件呢?不要寻找my.cnf文件,试着运行:
grep -r datadir /etc/mysql/
这将找到所有提到datadir的地方。在我的例子中,它产生了这样的答案:
/etc/mysql/mariadb.conf.d/50-server.cnf:datadir = /var/lib/mysql
当我编辑该文件(/etc/mysql/mariadb.conf.d/50-server.cnf)来更改datadir的值时,它起作用了,而在my.cnf中更改它不起作用。所以无论你想改变什么选择,试着用这种方式来寻找。