1

If I want to replicate how the MySQL/Maria client reads ~/.my.cnf, /etc/my.cnf, etc, how would I do it?

The MySQL docs give a list of paths and mention "top files are read first, files read later take precedence", is that on a key-value basis or the entire file?

1

The standard config file format applies. It is on group and key basis.

So if you have:

[mysql]
some_variable = 1

[client]
some_variable = 3

and after another file has

[mysql]
some_variable = 2

Then some_variable under mysql will be 2 but under client it will stay 3.

The only relevant part for MySQL server is the [mysqld] though.

The easiest way to determine which files are being read is to strace the mysql process on startup.

  1. Start MySQL with the normal init script and run ps -ef|grep mysqld.
  2. Copy /usr/sbin/mysqld
  3. Then run strace on the command grepping .cnf.

You should see something like this:

$ strace /usr/sbin/mysqld --basedir=/usr --datadir=/databases/mysql/data --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/log/mysql/mysql-error.log --pid-file=/databases/mysql/data/server.local.pid --socket=/var/run/mysqld/mysqld.sock --port=3306 2>&1 |grep .cnf
stat("/etc/my.cnf", 0x7fffa6edeb40)     = -1 ENOENT (No such file or directory)
stat("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=5454, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY)     = 3
stat("/usr/etc/my.cnf", 0x7fffa6edeb40) = -1 ENOENT (No such file or directory)
stat("/root/.my.cnf", {st_mode=S_IFREG|0644, st_size=73, ...}) = 0
open("/root/.my.cnf", O_RDONLY)         = 3
stat("/root/.mylogin.cnf", 0x7fffa6edeb40) = -1 ENOENT (No such file or directory)
stat("./auto.cnf", {st_mode=S_IFREG|0660, st_size=56, ...}) = 0
open("./auto.cnf", O_RDONLY)            = 13
stat("/root/.mylogin.cnf", 0x7fffa6edeb40) = -1 EACCES (Permission denied)
  • The server will read those files, but won't read any of those variables -- it looks only at [mysqld]. – Rick James Nov 14 '16 at 20:05
  • Yes, of course. I should have mentioned that this is only for example. I'll edit the answer to clarify. Thanks! – Károly Nagy Nov 15 '16 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.