Is there a command to determine which configuration file MySQL 5.0 is currently using?
If you are on Linux, then start the 'mysqld' with strace
, for eg strace ./mysqld
.
Among all the other system calls, you will find something like:
stat64("/etc/my.cnf", 0xbfa3d7fc) = -1 ENOENT (No such file or directory)
stat64("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=4227, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY|O_LARGEFILE) = 3
So, as you can see..it lists the .cnf files, that it attempts to use and finally uses.
ps auxf
and find the command executed for MySQL. Typically it look like something such as mysqld --basedir=/usr/local/mysql ...
(note the ... just means that there may be more flags in the command but I won't list all of it) Once you've found it, copy the whole thing and then shutdown MySQL. If you're on Linux it is /etc/init.d/mysqld stop
or mysqladmin -u root -p shutdown
. Then run strace
with the mysql command you copied. So it would look like so: strace mysqld --basedir=/usr/local/mysql
–
Friesen open(...
line. Instead I have 4 lines that end with = -1 Err#2
. How do you I know now which file is loaded? –
Sinegold sudo dtruss mysqld 2>&1|grep my.cnf
@mgPePe, that output likely means that none of the files was found so none were opened. –
Elate Taken from the fantastic "High Performance MySQL" O'Reilly book:
$ which mysqld
/usr/sbin/mysqld
$ /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"
Default options are read from the following files in the given order:
/etc/mysql/my.cnf ~/.my.cnf /usr/etc/my.cnf
!includedir
. I'm trying to figure out why the !includedir
directive in my /etc/mysql/my.cnf
file is not working. –
Haupt mysqld
with the full path?! –
Jilt If you run mysql --verbose --help | less
it will tell you about line 11 which .cnf
files it will look for.
You can also do mysql --print-defaults
to show you how the configuration values it will use for the client session in configuration file [client]. This can also be useful in identifying just which config file it is loading.
For server configuration session [mysqld] you can use:
mysqld --print-defaults
mysqld
instead of mysql
–
Pasty mysqld --print-defaults
, it gave me exactly what I wanted when I googled this question. –
Arterialize If you are on Linux, then start the 'mysqld' with strace
, for eg strace ./mysqld
.
Among all the other system calls, you will find something like:
stat64("/etc/my.cnf", 0xbfa3d7fc) = -1 ENOENT (No such file or directory)
stat64("/etc/mysql/my.cnf", {st_mode=S_IFREG|0644, st_size=4227, ...}) = 0
open("/etc/mysql/my.cnf", O_RDONLY|O_LARGEFILE) = 3
So, as you can see..it lists the .cnf files, that it attempts to use and finally uses.
ps auxf
and find the command executed for MySQL. Typically it look like something such as mysqld --basedir=/usr/local/mysql ...
(note the ... just means that there may be more flags in the command but I won't list all of it) Once you've found it, copy the whole thing and then shutdown MySQL. If you're on Linux it is /etc/init.d/mysqld stop
or mysqladmin -u root -p shutdown
. Then run strace
with the mysql command you copied. So it would look like so: strace mysqld --basedir=/usr/local/mysql
–
Friesen open(...
line. Instead I have 4 lines that end with = -1 Err#2
. How do you I know now which file is loaded? –
Sinegold sudo dtruss mysqld 2>&1|grep my.cnf
@mgPePe, that output likely means that none of the files was found so none were opened. –
Elate I am on Windows and I have installed the most recent version of MySQL community 5.6
What I did to see what configuration file uses was to go to Administrative Tools > Services > MySQL56 > Right click > Properties and check the path to executable:
"C:/Program Files/MySQL/MySQL Server 5.6/bin\mysqld" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.6\my.ini" MySQL56
C:\ProgramData\MySQL\MySQL Server 5.7\my.ini
by default. –
Cubby An alternative is to use
mysqladmin variables
mysqld --help --verbose is dangerous. You can easily overwrite pidfile for running instance! use it with --pid-file=XYZ
Oh, and you can't really use it if you have more than 1 instance running. It will only show you default value.
Really good article about it:
Just did a quick test on ubuntu:
installed mysql-server, which created /etc/mysql/my.cnf
mysqld --verbose --help | grep -A 1 "Default options"
110112 13:35:26 [Note] Plugin 'FEDERATED' is disabled.
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
created /etc/my.cnf and /usr/etc/my.cnf, each with a different port number
restarted mysql - it was using the port number set in /usr/etc/my.cnf
Also meanwhile found the --defaults-file option to the mysqld. If you specify a config file there, only that one will be used, regardless of what is returned by /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"
I found this really useful:
- Find the MySQL process in Services under
Control Panel -> Administration Tools
- Right mouse click and choose
Properties
- Click and select the
Path to executable
and see if it contains the path to themy.ini/my.cfg
Some servers have multiple MySQL versions installed and configured. Make sure you are dealing with the correct version running with a Unix command of:
ps -ax | grep mysql
For people running windows server with mysql as a service, an easy way to find out what config file you are running is to open up the services control panel, find your mysql service (in my case 'MYSQL56'), right click and click properties. Then from here you can check the "Path to Executable" which should have a defaults-file
switch which points to where your config file is.
Just in case you are running mac this can be also achieved by:
sudo dtruss mysqld 2>&1 | grep cnf
If you are on Windows, you can use Sysinternals procmon. Open it and configure filter setting like this, then click "Add". Now procmon will monitor mysqld.
Now start your mysql server as normal. Procmon will capture mysql's background operations. Search "my." in the procmon result pane and you will find something like the following:
It's clear that mysql searches a list of configuration files in turn. In my case it found C:\mysql-5.7.19-winx64\my.cnf
successfully so it's using this one.
Make sure you're getting the correct files, especially if you have multiple versions of MySQL installed, for example, using tools like DBNgin.
This is what I did to find the correct file on Max (should work with Linux too):
Run ps ax|grep mysqld
to list the running daemons:
36245 ?? S 18:46.08 /Users/Shared/DBngin/mysql/8.0.33/bin/mysqld --socket=/tmp/mysql_3306.sock
1: Check if --no-defaults
, --defaults-file
or --defaults-extra-file
exists there.
2: Check the default locations:
/Users/Shared/DBngin/mysql/8.0.33/bin/mysqld -v --help|more
3: Also make sure that defaults are not overridden
/Users/Shared/DBngin/mysql/8.0.33/bin/mysqld --print-defaults
See also the official documentation.
On CentOS and MariaDB you will find the MariaDB Server configuration settings in: /etc/my.cnf.d/server.cnf
© 2022 - 2024 — McMap. All rights reserved.