简体   繁体   English

如何在linux中找出当前使用的MySQL配置文件的位置

[英]How to find out the location of currently used MySQL configuration file in linux

How do I know which configuration file is used by MySQL currently?我如何知道 MySQL 当前使用的是哪个配置文件? Is there any command or something to find it out?有什么命令或东西可以找到它吗?

The information you want can be found by running可以通过运行找到你想要的信息

mysql --help

or或者

mysqld --help --verbose

I tried this command on my machine:我在我的机器上试过这个命令:

mysql --help | grep "Default options" -A 1

And it printed out:它打印出来:

Default options are read from the following files in the given order:
/etc/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

See if that works for you.看看这是否适合你。

mysqld --help --verbose will find only location of default configuration file. mysqld --help --verbose 只会找到默认配置文件的位置。 What if you use 2 MySQL instances on the same server?如果您在同一台服务器上使用 2 个 MySQL 实例怎么办? It's not going to help.它不会有帮助。

Good article about figuring it out:关于弄清楚的好文章:

"How to find MySQL configuration file?" “如何找到MySQL配置文件?”

如果您使用终端,只需键入以下内容:

locate my.cnf

您可以使用报告进程状态ps命令:

ps ax | grep '[m]ysqld'

You should find them by default in a folder like /etc/my.cnf , maybe also depends on versions.默认情况下,您应该在/etc/my.cnf类的文件夹中找到它们,也许还取决于版本。 From MySQL Configuration File :MySQL 配置文件

Interestingly, the scope of this file can be set according to its location.有趣的是,这个文件的范围可以根据它的位置来设置。 The settings will be considered global to all MySQL servers if stored in /etc/my.cnf.如果存储在 /etc/my.cnf 中,这些设置将被视为所有 MySQL 服务器的全局设置。 It will be global to a specific server if located in the directory where the MySQL databases are stored (/usr/local/mysql/data for a binary installation, or /usr/local/var for a source installation).如果位于存储 MySQL 数据库的目录中(二进制安装的 /usr/local/mysql/data 或源安装的 /usr/local/var ),它将对特定服务器是全局的。 Finally, its scope could be limited to a specific user if located in the home directory of the MySQL user (~/.my.cnf).最后,如果它位于 MySQL 用户的主目录 (~/.my.cnf) 中,则其范围可能仅限于特定用户。 Keep in mind that even if MySQL does locate a my.cnf file in /etc/my.cnf (global to all MySQL servers on that machine), it will continue its search for a server-specific file, and then a user-specific file.请记住,即使 MySQL 确实在 /etc/my.cnf 中找到了 my.cnf 文件(该机器上所有 MySQL 服务器的全局文件),它也会继续搜索特定于服务器的文件,然后是特定于用户的文件文件。 You can think of the final configuration settings as being the result of the /etc/my.cnf, mysql-data-dir/my.cnf, and ~/.my.cnf files.您可以将最终配置设置视为 /etc/my.cnf、mysql-data-dir/my.cnf 和 ~/.my.cnf 文件的结果。

There are a few switches to package managers to list specific files.有几个包管理器的开关来列出特定的文件。

RPM Sytems:转速系统:

There are switches to rpm command, -q for query, and -c or --configfiles to list config files.rpm命令的开关, -q用于查询, -c--configfiles用于列出配置文件。 There is also -l or --list还有-l--list

The --configfiles one didn't quiet work for me, but --list did list a few .cnf files held by mysql-server --configfiles对我来说并没有安静的工作,但是--list确实列出了mysql-server持有的一些.cnf文件

rpm -q --list mysql-server

DEB Systems: DEB系统:

Also with limited success: dpkg --listfiles mysql-server也取得了有限的成功: dpkg --listfiles mysql-server

you can find it by running the following command您可以通过运行以下命令找到它

mysql --help

it will give you the mysql installed directory and all commands for mysql.它将为您提供 mysql 安装目录和 mysql 的所有命令。

login to mysql with proper credential and used mysql>SHOW VARIABLES LIKE 'datadir';使用适当的凭据登录到 mysql 并使用 mysql>SHOW VARIABLES LIKE 'datadir'; that will give you path of where mysql stored这将为您提供 mysql 存储位置的路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM