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


当前回答

我不知道你是如何在Linux环境下安装MySQL的,但你检查过吗?

/etc/my.cnf

其他回答

Ubuntu 16: /etc/mysql/mysql.conf.d/mysqld.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

你可以使用:

locate my.cnf
whereis my.cnf
find . -name my.cnf

仅回答MySQL工作台用户,

实际上,你可以“请求”MySQL提供它搜索my.cnf(或Windows上的my.ini)的所有位置的列表。但它不是SQL查询。相反,执行:

$ mysqladmin --help

或者,5.7之前:

$ mysqld --help --verbose

在最初几行中,您将发现一条消息,其中包含它要查找的所有my.cnf位置的列表。在我的机器上是:

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

或者,在Windows上:

Default options are read from the following files in the given order:
C:\Windows\my.ini
C:\Windows\my.cnf
C:\my.ini
C:\my.cnf
C:\Program Files\MySQL\MySQL Server 5.5\my.ini
C:\Program Files\MySQL\MySQL Server 5.5\my.cnf

但是请注意,在这些位置中都可能没有my.cnf文件。因此,您可以自己创建这个文件——使用MySQL发行版提供的一个配置文件示例(在Linux上——请参阅/usr/share/mysql/*.cnf文件并使用适合您的文件——将其复制到/etc/my.cnf,然后根据需要进行修改)。

另外,请注意还有一个命令行选项——defaults-file,它可以定义my.cnf或my.ini文件的自定义路径。例如,Windows上的MySQL 5.5就是这种情况——它指向data目录中的my.ini文件,通常不会在mysqld——help——verbose中列出。在Windows上-请参阅服务属性以确定是否适合您。

最后,查看https://dev.mysql.com/doc/refman/8.0/en/option-files.html—那里有更详细的描述。