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


当前回答

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

其他回答

你可以在终端上运行查找。

find / -name my.cnf

这可能有用:

strace mysql ";" 2>&1  | grep cnf

在我的机器上输出:

stat64("/etc/my.cnf", 0xbf9faafc)       = -1 ENOENT (No such file or directory)
stat64("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=4271, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY|O_LARGEFILE) = 3
read(3, "# /etc/mysql/my.cnf: The global "..., 4096) = 4096
stat64("/home/xxxxx/.my.cnf", 0xbf9faafc) = -1 ENOENT (No such file or directory)

因此,看起来/etc/mysql/my.cnf是一个,因为它的stat64()和read()是成功的。

仅回答MySQL工作台用户,

你必须根据你的MySQL版本查找不同的位置。

mysqld --help -verbose | grep my.cnf

For Homebrew:
/usr/local/Cellar/mysql/8.0.11/bin/mysqld (mysqld 8.0.11)

Default possible locations:
/etc/my.cnf
/etc/mysql/my.cnf
~/.my.cnf

Found mine here: 
/usr/local/etc/my.cnf

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

例如:my.cnf在哪里