如何在linux中找出当前使用的MySQL配置文件的位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3270326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find out the location of currently used MySQL configuration file in linux
提问by Albin Joseph
How do I know which configuration file is used by MySQL currently? Is there any command or something to find it out?
我如何知道 MySQL 当前使用的是哪个配置文件?有什么命令或东西可以找到它吗?
采纳答案by GoalBased
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.
看看这是否适合你。
回答by bakkal
You should find them by default in a folder like /etc/my.cnf
, maybe also depends on versions. From MySQL Configuration File:
默认情况下,您应该在 文件夹中找到它们/etc/my.cnf
,也许还取决于版本。从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. 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). Finally, its scope could be limited to a specific user if located in the home directory of the MySQL user (~/.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. 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 服务器的全局设置。如果位于存储 MySQL 数据库的目录中(二进制安装的 /usr/local/mysql/data 或源安装的 /usr/local/var ),它将对特定服务器是全局的。最后,如果它位于 MySQL 用户的主目录 (~/.my.cnf) 中,则其范围可能仅限于特定用户。请记住,即使 MySQL 确实在 /etc/my.cnf 中找到了 my.cnf 文件(该机器上所有 MySQL 服务器的全局文件),它也会继续搜索特定于服务器的文件,然后是特定于用户的文件文件。您可以将最终配置设置视为 /etc/my.cnf、mysql-data-dir/my.cnf 和 ~/.my 的结果。
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. There is also -l
or --list
有用于rpm
命令、-q
查询和/-c
或--configfiles
列出配置文件的开关。还有-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
确实列出了一些.cnf
由mysql-server
rpm -q --list mysql-server
DEB Systems:
DEB系统:
Also with limited success: dpkg --listfiles mysql-server
也取得了有限的成功: dpkg --listfiles mysql-server
回答by Sasha
mysqld --help --verbose will find only location of default configuration file. What if you use 2 MySQL instances on the same server? It's not going to help.
mysqld --help --verbose 只会找到默认配置文件的位置。如果您在同一台服务器上使用 2 个 MySQL 实例怎么办?它不会有帮助。
Good article about figuring it out:
关于弄清楚的好文章:
回答by Aventador
If you are using terminal just type the following:
如果您使用终端,只需键入以下内容:
locate my.cnf
回答by DanM7
回答by Shyam Gupta
login to mysql with proper credential and used mysql>SHOW VARIABLES LIKE 'datadir'; that will give you path of where mysql stored
使用适当的凭据登录到 mysql 并使用 mysql>SHOW VARIABLES LIKE 'datadir'; 这将为您提供 mysql 存储位置的路径
回答by Mahi Gunjal
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 的所有命令。