确定正在使用哪个 MySQL 配置文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/580331/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 12:50:15  来源:igfitidea点击:

Determine which MySQL configuration file is being used

mysqlconfiguration

提问by yalestar

Is there a command to determine which configuration file MySQL 5.0 is currently using?

是否有命令可以确定 MySQL 5.0 当前正在使用哪个配置文件?

采纳答案by staticsan

If you are on Linux, then start the 'mysqld' with strace, for eg strace ./mysqld.

如果您使用的是 Linux,则使用 启动 'mysqld' strace,例如strace ./mysqld.

Among all the other system calls, you will find something like:

在所有其他系统调用中,您会发现如下内容:

stat64("/etc/my.cnf", 0xbfa3d7fc)       = -1 ENOENT (No such file or directory)
stat64("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=4227, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY|O_LARGEFILE) = 3

So, as you can see..it lists the .cnf files, that it attempts to use and finally uses.

因此,如您所见……它列出了它尝试使用并最终使用的 .cnf 文件。

回答by Mark B

Taken from the fantastic "High Performance MySQL" O'Reilly book:

摘自 O'Reilly 出色的“高性能 MySQL”一书中:

$ which mysqld
/usr/sbin/mysqld

$ /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"
Default options are read from the following files in the given order:
/etc/mysql/my.cnf ~/.my.cnf /usr/etc/my.cnf

回答by staticsan

If you run mysql --verbose --help | lessit will tell you about line 11 which .cnffiles it will look for.

如果你运行mysql --verbose --help | less它,它会告诉你第 11 行.cnf它将寻找哪些文件。

You can also do mysql --print-defaultsto show you how the configuration values it will use. This can also be useful in identifying just which config file it is loading.

您还可以mysql --print-defaults向您展示它将如何使用配置值。这对于识别正在加载的配置文件也很有用。

回答by Alexandru Trandafir Catalin

I am on Windows and I have installed the most recent version of MySQL community 5.6

我在 Windows 上安装了最新版本的 MySQL 社区 5.6

What I did to see what configuration file uses was to go to Administrative Tools > Services > MySQL56 > Right click > Properties and check the path to executable:

我所做的查看配置文件使用的是转到管理工具>服务> MySQL56>右键单击>属性并检查可执行文件的路径:

"C:/Program Files/MySQL/MySQL Server 5.6/bin\mysqld" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.6\my.ini" MySQL56

"C:/Program Files/MySQL/MySQL Server 5.6/bin\mysqld" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.6\my.ini" MySQL56

回答by Steve

An alternative is to use

另一种方法是使用

mysqladmin variables

回答by Sasha

mysqld --help --verbose is dangerous. You can easily overwrite pidfile for running instance! use it with --pid-file=XYZ

mysqld --help --verbose 是危险的。您可以轻松覆盖运行实例的 pidfile!与 --pid-file=XYZ 一起使用

Oh, and you can't really use it if you have more than 1 instance running. It will only show you default value.

哦,如果你有超过 1 个实例在运行,你就不能真正使用它。它只会显示您的默认值。

Really good article about it:

关于它的文章非常好:

How to find MySQL configuration file?

如何找到MySQL配置文件?

回答by Herta

Just did a quick test on ubuntu:

刚刚在ubuntu上做了一个快速测试:

  • installed mysql-server, which created /etc/mysql/my.cnf

  • mysqld --verbose --help | grep -A 1 "Default options"

  • 安装了mysql-server,它创建了/etc/mysql/my.cnf

  • mysqld --verbose --help | grep -A 1 "默认选项"

110112 13:35:26 [Note] Plugin 'FEDERATED' is disabled.
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

110112 13:35:26 [注意] 插件“联邦”已禁用。
默认选项按给定顺序从以下文件中读取: /etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

  • created /etc/my.cnf and /usr/etc/my.cnf, each with a different port number

  • restarted mysql - it was using the port number set in /usr/etc/my.cnf

  • 创建 /etc/my.cnf 和 /usr/etc/my.cnf,每个都有不同的端口号

  • 重新启动 mysql - 它使用在 /usr/etc/my.cnf 中设置的端口号

Also meanwhile found the --defaults-file option to the mysqld. If you specify a config file there, only that one will be used, regardless of what is returned by /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"

同时还发现了 mysqld 的 --defaults-file 选项。如果您在那里指定一个配置文件,则只会使用那个配置文件,而不管 /usr/sbin/mysqld --verbose --help | 返回什么内容。grep -A 1 "默认选项"

回答by fanThomas

Using MySQL Workbench it will be shown under "Server Status": enter image description here

使用 MySQL Workbench,它将显示在“服务器状态”下: 在此处输入图片说明

回答by Luke

I found this really useful:

我发现这非常有用:

  1. Find the MySQL process in Services under Control Panel -> Administration Tools
  2. Right mouse click and choose Properties
  3. Click and select the Path to executableand see if it contains the path to the my.ini/my.cfg
  1. 在Services下找到MySQL进程 Control Panel -> Administration Tools
  2. 鼠标右键单击并选择 Properties
  3. 单击并选择Path to executable并查看它是否包含到my.ini/my.cfg

回答by Heather McVay

Some servers have multiple MySQL versions installed and configured. Make sure you are dealing with the correct version running with a Unix command of:

一些服务器安装和配置了多个 MySQL 版本。确保您正在处理使用 Unix 命令运行的正确版本:

ps -ax | grep mysql