是否有一个MySQL命令来定位my.cnf配置文件,类似于PHP的phpinfo()定位它的PHP .ini?


当前回答

另一个选项是使用whereis命令。

例如:my.cnf在哪里

其他回答

仅回答MySQL工作台用户,

所有很棒的建议,在我的情况下,我没有在任何这些位置找到它,但在/usr/share/mysql,我有一个RHEL虚拟机,我安装了mysql5.5

对于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.
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

正如konyak所指出的,你可以通过运行mysqladmin——help来获得mysql将查找my.cnf文件的位置列表。因为这是相当啰嗦的,你可以快速得到你关心的部分:

$ mysqladmin --help | grep -A1 'Default options'

这将给你类似的输出:

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

根据你安装mysql的方式,有可能这些文件都不存在。您可以使用cat来查看您的配置是如何构建的,并在需要时在您的首选位置创建自己的my.cnf。