How to find configuration file MySQL uses? Go

Source: Internet
Author: User

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 the their production MySQL inst Ances. From the description I am given it appeared that their server had at least six different copies of my.cnf file in Differen T locations on disk. And all were similar enough, each could actually is the one. All superfluous files were the result of a bit negligent system administration. So why turned to being the quickest and the least destructive to find the correct one?

Initially suspecting the server is simply running more than just one MySQL instance, I logged on 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 the 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 has to work every time. If configuration file is not specified explicitly by a init script starting the MySQL instance, then database would used The compiled-in default and such information would not being visible in the ps output. This could happen if for example the database instance is launched "by hand" from the shell. The file information would also not being visible if the process line is truncated for any.

An alternative method could being examining information in. Are the place /proc /proc where Linux kernel exposes a lot of inte Rnal information about itself, hardware and running processes through a bunch of virtual files and directories. Specifically each process have its own directory there this takes the name after the process ID (or PID ). Learning MySQL is as easy as PID 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 '/usr/sbin/mysqld--defaults-file=/etc/mysql/my.cnf ' \ n '

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

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

Server ~ # tr ' "\ n ' </proc/$ (pidof mysqld)/environ | Grep-i cnfmy_cnf=/etc/mysql/my.cnf

Finally You can try figuring out the compiled-in defaults and it won ' t necessarily tell you which configuration was Actua Lly used. This method was also not 100% safe as it means attempting to start another MySQL instance, even if only to print help Messa GE, 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 is read ' default options is read from the following files in the given order:/etc/my.cnf/etc/m YSQL/MY.CNF ~/.my.cnf

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

All of all I am able to help my customer. But there is no foolproof. It might happen, in certain circumstances figuring out, the true location is not my.cnf possible.

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

How to find configuration file MySQL uses? Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.