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

前端 未结 7 550
慢半拍i
慢半拍i 2020-12-23 13:06

How do I know which configuration file is used by MySQL currently? Is there any command or something to find it out?

相关标签:
7条回答
  • 2020-12-23 13:52

    You should find them by default in a folder like /etc/my.cnf, maybe also depends on versions. From MySQL Configuration File:

    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.

    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

    The --configfiles one didn't quiet work for me, but --list did list a few .cnf files held by mysql-server

    rpm -q --list mysql-server
    

    DEB Systems:

    Also with limited success: dpkg --listfiles mysql-server

    0 讨论(0)
  • 2020-12-23 13:55

    You can use the report process status ps command:

    ps ax | grep '[m]ysqld'
    
    0 讨论(0)
  • 2020-12-23 13:59

    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.

    Good article about figuring it out:

    "How to find MySQL configuration file?"

    0 讨论(0)
  • 2020-12-23 14:02

    If you are using terminal just type the following:

    locate my.cnf
    
    0 讨论(0)
  • 2020-12-23 14:04

    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.

    0 讨论(0)
  • 2020-12-23 14:08

    you can find it by running the following command

    mysql --help
    

    it will give you the mysql installed directory and all commands for mysql.

    0 讨论(0)
提交回复
热议问题