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


当前回答

仅回答MySQL工作台用户,

其他回答

正如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提供它搜索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—那里有更详细的描述。

这可能有用:

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()是成功的。

对我来说,这是我有“ENGINE=MyISAM”类型的表,一旦我改变它为“ENGINE=InnoDB”它工作了:) 在PhpMyAdmin在Azure应用程序服务:)

你必须根据你的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