How do I find the MySQL my.cnf location

2019-01-01 05:55发布

Is there a MySQL command to locate the my.cnf configuration file, similar to how PHP's phpinfo() locates its php.ini?

标签: mysql linux
18条回答
弹指情弦暗扣
2楼-- · 2019-01-01 06:38

Answered for only MySQL Workbench users,

enter image description here

查看更多
不流泪的眼
3楼-- · 2019-01-01 06:39

I don't know how you've setup MySQL on your Linux environment but have you checked?

  • /etc/my.cnf
查看更多
君临天下
4楼-- · 2019-01-01 06:40

Found mine using

mysqld --help --verbose | grep my.cnf
查看更多
后来的你喜欢了谁
5楼-- · 2019-01-01 06:40

Another option is to use the whereis command.

E.g. whereis my.cnf

查看更多
笑指拈花
6楼-- · 2019-01-01 06:42

I installed xampp bundle with apache, php and mysql in ubuntu. There my.cnf file is located in /opt/lampp/etc/ folder. Hope it'll help somebody.

查看更多
姐姐魅力值爆表
7楼-- · 2019-01-01 06:43

You can actually "request" MySQL for a list of all locations where it searches for my.cnf (or my.ini on Windows). It is not an SQL query though. Rather, execute:

$ mysqladmin --help

or, prior 5.7:

$ mysqld --help --verbose

In the very first lines you will find a message with a list of all my.cnf locations it looks for. On my machine it is:

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

Or, on Windows:

Default options are read from the following files in the given order:
C:\Windows\my.ini
C:\Windows\my.cnf
C:\my.ini
C:\my.cnf
C:\Program Files\MySQL\MySQL Server 5.5\my.ini
C:\Program Files\MySQL\MySQL Server 5.5\my.cnf

Note however, that it might be the case that there is no my.cnf file at any of these locations. So, you can create the file on your own - use one of the sample config files provided with MySQL distribution (on Linux - see /usr/share/mysql/*.cnf files and use whichever is appropriate for you - copy it to /etc/my.cnf and then modify as needed).

Also, note that there is also a command line option --defaults-file which may define custom path to my.cnf or my.ini file. For example, this is the case for MySQL 5.5 on Windows - it points to a my.ini file in the data directory, which is not normally listed with mysqld --help --verbose. On Windows - see service properties to find out if this is the case for you.

Finally, check the https://dev.mysql.com/doc/refman/8.0/en/option-files.html - it is described there in more details.

查看更多
登录 后发表回答