是否有一个MySQL命令来定位my.cnf配置文件,类似于PHP的phpinfo()定位它的PHP .ini?
当前回答
如果你使用的是Debian/Ubuntu系统,并且已经配备了现代版本的数据库(从5.7以上,mysql 8也适用),找到我发现的实际.cnf文件的最佳方法是:
sudo update-alternatives --config my.cnf
你应该看到如下输出:
There are 3 choices for the alternative my.cnf (providing /etc/mysql/my.cnf).
Selection Path Priority Status
------------------------------------------------------------
0 /etc/mysql/mariadb.cnf 500 auto mode
1 /etc/mysql/mariadb.cnf 500 manual mode
2 /etc/mysql/my.cnf.fallback 100 manual mode
* 3 /etc/mysql/mysql.cnf 300 manual mode
在/etc/mysql/mysql.cnf中有两行值得注意:
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
MySQL会在/etc/ MySQL /conf目录下寻找所有的.cnf文件。/etc/mysql/mysql.conf. D /
调优快乐!
其他回答
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
我不知道你是如何在Linux环境下安装MySQL的,但你检查过吗?
/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。
MySQL配置文件:
/etc/my.cnf
另一个选项是使用whereis命令。
例如:my.cnf在哪里