How to find configuration file MySQL uses?(转)

http://www.dbasquare.com/2012/04/01/how-to-find-mysql-configuration-file/

A customer called me today asking for help with locating the configuration file used by one of their production MySQL instances. From the description I was given it appeared that their server had at least six different copies of my.cnf file in different locations on disk. And all were similar enough that each could actually be the one. All superfluous files were the result of a bit negligent system administration. So what turned to be the quickest and the least destructive way to find the correct one?

Initially suspecting the server was simply running more than just one MySQL instance, I logged in to take a deeper look. But I found only one mysqld process and, indeed, several configuration files.

All of them seemed good candidates:

/etc/my.cnf
/etc/mysql/my.cnf
/var/lib/mysql/my.cnf
...

In many cases you could simply check system process list using ps:

server ~ # ps ax | grep ‘[m]ysqld‘
10801 ?        Ssl    0:27 /usr/sbin/mysqld --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/lib/mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock

In many cases, because it doesn’t really have to work every time. If configuration file was not specified explicitly by an init script starting the MySQL instance, then database would used the compiled-in default and such information would not be visible in the ps output. This could happen if for example the database instance was launched “by hand” from shell. The file information would also not be visible if the process line was truncated for any.

An alternative method could be examining information in /proc. /proc is the place where Linux kernel exposes a lot of internal information about itself, hardware and running processes through a bunch of virtual files and directories. Specifically each process has its own directory there that takes the name after the process id (or PID). Learning MySQLPID is as easy as running pidof mysqld.

One of the files we need is called cmdline. It contains the full command that started certain process.

server ~ # cat /proc/$(pidof mysqld)/cmdline | tr ‘\0‘ ‘\n‘
/usr/sbin/mysqld
--defaults-file=/etc/mysql/my.cnf

The configuration information is clearly visible. The tr command simply converts any \0 characters into line breaks and is there just for readability.

Yet another approach could be browsing the process environment information. It can also be found in /proc in a file called environ. Sometimes a startup script may leave some information there:

server ~ # tr ‘\0‘ ‘\n‘ < /proc/$(pidof mysqld)/environ | grep -i cnf
MY_CNF=/etc/mysql/my.cnf

Finally you can try figuring out the compiled-in defaults, but it won’t necessarily tell you which configuration was actually used. This method is also not 100% safe as it means attempting to start another MySQL instance, even if only to print help message, because MySQL does not seem to handle this very well and it may produce some conflicts:

server ~ # /usr/sbin/mysqld --help --verbose --skip-networking --pid-file=$(tempfile) 2> /dev/null | grep -A1 ‘Default options are read‘
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf

Specifying --pid-file here is essential as otherwise the new mysqld may overwrite the PID file of the running instance.

All in all I was able to help my customer. But there is no foolproof way. It might happen that in certain circumstances figuring out the true my.cnf location may not be possible.

http://www.cnblogs.com/AloneSword/p/3396140.html

时间: 2024-10-17 22:17:27

How to find configuration file MySQL uses?(转)的相关文章

安装mysql时 Write configuration file 错误的解决办法

原因1:mysql的安装路径不能包含字符或者中文. 原因2:select a server type时选择了Server Machine项,write configuration file报错. 解决办法:修改安装路径重新安装.select a server type选择developer Machine项(开发测试类选用)

springMVC+mybatis 进行单元测试时 main SqlSessionFactoryBean - Parsed configuration file: &#39;class path resource&#39; 无限的读取xml文件

今天终于写完的Dao层的操作,怀着无比激动的心情,进行单元测试,就在最后一个方法,对的就是最后一个方法,启动单元测试就会报以下错误: [2016-05-11 18:25:01,691] [WARN ] main BoneCPConfig - Please use setIdleConnectionTestPeriodInMinutes in place of setIdleConnectionTestPeriod. This method has been deprecated. [2016-0

phpmyadmin Wrong permissions on configuration file, should not be world writable!

巴拉巴拉,实际场景是这样,因为有需要,所以想用django 做个rest服务给其他平台提供服务,发现以前正常的页面都无法运行,奇怪发现有一个页面提示连接不上mysql 难道mysql挂了,打开phpmyadmin 提示如标题,进入到init.d 准备查看下状态 提示 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) 咦,mysql 坏

log4j报错ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. log4j版本:log4j-core-2.7.jar   log4j-api-2.7.jar log4j2只支持xml和json两种格式的配置,所以配置log4j.properties时,是没有作用的. log4j 2.0与以往的1.x有一个明显的不同,其配置

Struts2 ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging

在做struts2时导包完成发现Struts2 ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging log4j2的配置文件没找到去struts2-blank下.WEB-INF\classes下找到log4j的配置文件log4j2.xml:把他放入src中

im-switch -s ibus错误:Error: no configuration file &quot;ibus&quot; exists.

在虚拟机上安装Ubuntu14.04 后安装ibus输入法,万万没想到在切换输入法的时候居然出错了! 无语了,再网上查了一下,这个错误出现的还是比较少的. 先说Ubuntu输入法(ibus)安装的一般步骤吧. 一.安装语言包 System Settings-->Language Support-->Install/Remove Languages 安装时间会稍微长一点.完成后注销一下. 如果不想安装中文语言包,则需要安装中文字体: $ sudo apt-get install ttf-wqy-

VMware强制关闭,造成(failed to get exclusive lock on the configuration file...)错误

参考文章:http://blog.csdn.net/qyee16/article/details/6764753 笔记本蓝屏,造成VMware非法关闭,开机重启VMware后,发现无法打开虚拟机了,报错如下: 点击确定后,出现Internal Error错误: 解决办法很简单,打开任务管理器 --> 进程,然后把所有vmware相关的进程都关闭,在重新打开vmware就好了: 红框中为需要关闭的进程 VMware强制关闭,造成(failed to get exclusive lock on th

Could not find qmake configuration file win32-g++

D:\Source>c:\Qt\Qt5.3.2_static\bin\qmake -makefile -o Makefile my.proCould not find qmake configuration file win32-g++.Error processing project file: my.pro -------------------------------------------------------------------- 其实是丢失了以前的静态库路径. 办法: D:\S

Could not parse configuration: file:/D:/apache-tomcat-7.0.55-windows-x64/apache-tomcat-7.0.55/webapp

在做ssh项目时,启动tomcat,出现了以下的错误 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ins