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:49

For Ubuntu 16: /etc/mysql/mysql.conf.d/mysqld.cnf

查看更多
倾城一夜雪
3楼-- · 2019-01-01 06:51

All great suggestions, in my case I didn't find it in any of those locations, but in /usr/share/mysql, I have a RHEL VM and I installed mysql5.5

查看更多
与风俱净
4楼-- · 2019-01-01 06:54

There is no internal MySQL command to trace this, it's a little too abstract. The file might be in 5 (or more?) locations, and they would all be valid because they load cascading.

  • /etc/my.cnf
  • /etc/mysql/my.cnf
  • $MYSQL_HOME/my.cnf
  • [datadir]/my.cnf
  • ~/.my.cnf

Those are the default locations MySQL looks at. If it finds more than one, it will load each of them & values override each other (in the listed order, I think). Also, the --defaults-file parameter can override the whole thing, so... basically, it's a huge pain in the butt.

But thanks to it being so confusing, there's a good chance it's just in /etc/my.cnf.

(if you just want to see the values: SHOW VARIABLES, but you'll need the permissions to do so.)

查看更多
有味是清欢
5楼-- · 2019-01-01 06:55

As noted by konyak you can get the list of places mysql will look for your my.cnf file by running mysqladmin --help. Since this is pretty verbose you can get to the part you care about quickly with:

$ mysqladmin --help | grep -A1 'Default options'

This will give you output similar to:

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

Depending on how you installed mysql it is possible that none of these files are present yet. You can cat them in order to see how your config is being built and create your own my.cnf if needed at your preferred location.

查看更多
大哥的爱人
6楼-- · 2019-01-01 06:58

You can use :

locate my.cnf
whereis my.cnf
find . -name my.cnf
查看更多
姐姐魅力值爆表
7楼-- · 2019-01-01 06:59

This might work:

strace mysql ";" 2>&1  | grep cnf

on my machine this outputs:

stat64("/etc/my.cnf", 0xbf9faafc)       = -1 ENOENT (No such file or directory)
stat64("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=4271, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY|O_LARGEFILE) = 3
read(3, "# /etc/mysql/my.cnf: The global "..., 4096) = 4096
stat64("/home/xxxxx/.my.cnf", 0xbf9faafc) = -1 ENOENT (No such file or directory)

So it looks like /etc/mysql/my.cnf is the one since it stat64() and read() were successful.

查看更多
登录 后发表回答