How to Find the MySQL My.Cnf Location

How do I find the MySQL my.cnf location

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.)

Run mysql --help and you will see:

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

Sample Image

Determine which MySQL configuration file is being used

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.

Cannot locate the my.cnf file in MySQL 8.0 running on Windows 10

Mysql hides in a hidden folder ProgramData

C:\ProgramData\MySQL\MySQL Server 8.0

And windows uses

my.ini

not my.conf

I can't find the file my.cnf or my.ini

I guess you are on Windows because of the "MySQL Server x.0" folder name (on Mac & Linux, this folder name does not contain spaces by default).

No configuration file is created after a standard installation. You may create one if you have the need to specify any options. Otherwise every option has a default setting built into the MySQL Server.

On Windows, the MySQL Server searches several locations for the configuration file, so you can put the file in any of those locations.

See documentation for a list of the locations the server searches for the configuration file on Windows:

  • https://dev.mysql.com/doc/refman/8.0/en/windows-create-option-file.html
  • https://dev.mysql.com/doc/refman/8.0/en/option-files.html

Remember that after you edit the configuration file, you need to restart the MySQL Server. It reads the configuration options only when the server starts.

What is the location of mysql client .my.cnf in XAMPP for Windows?

Type this:

mysql --help 

Then look at the output. There is a block of text about 3/4 the way down describing what files it finds its defaults .my.cnf from. Here is an example from XAMPP v3.2.1, 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:\xampp\mysql\my.ini
C:\xampp\mysql\my.cnf
C:\xampp\mysql\bin\my.ini
C:\xampp\mysql\bin\my.cnf

Your setup may differ. You will have to run the command to check the actual paths on your particular system.

Where is MySQL 5.7 my.cnf file?

mysql --help printed below.

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

The following groups are read: mysql client
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit.
--no-defaults Don't read default options from any option file,
except for login file.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=#
Also read groups with concat(group, suffix)
--login-path=# Read this path from the login file.

Where can I find the file my.cnf or my.ini file?

I do not have Window present at the moment, but I think it should reside in the C:\WINDOWS\ directory.

When invoking help on GNU/Linux with mysql --help it shows (excerpt):

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

Maybe you can get the same information on Windows, too.

Btw: with mysql --version you can get your current version.

MySQL my.ini location

You have to look I the folder C:\Program Files\MySQL\MySQL Server 5.5 but there is a problem. When you perform an MSI install of MySQL, my.ini is not created. There will be sample .ini files in that folder. In order to use one of them, say my-medium.ini, you need to do the following before a MySQL restart:

cd C:\Program Files\MySQL\MySQL Server 5.5
copy my-medium.ini my.ini
net stop mysql
net start mysql

Once, you do this, my.ini can be read by C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe.



Related Topics



Leave a reply



Submit