是否有一个MySQL命令来定位my.cnf配置文件,类似于PHP的phpinfo()定位它的PHP .ini?
当前回答
如果您正在使用MAMP,请访问模板> MySQL (my.cnf) > [version]
如果您正在运行MAMP无窗口,您可能需要使用customize按钮定制工具栏。
其他回答
实际上,你可以“请求”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—那里有更详细的描述。
用户也可以执行该命令。
帮助| grep CNF
Ubuntu 16: /etc/mysql/mysql.conf.d/mysqld.cnf
如果你使用的是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 /
调优快乐!
对于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.