Where does my.cnf get stored in Linux?

Posted on

Question :

I am new to linux, and i just installed MySQL-server-5.1.59-1.glibc23.i386.rpm in my linux machine.

I wanted to know where my.cnf file gets stored..?
Will my.cnf gets created with the installation or not..?

I am using Fedora core 13

Edited: Still i am not able to find this file.
When i asked my admin, he is telling we need to copy my-large.cnf and place in /etc folder.. is it so…?

Answer :

Most likely /etc/my.cnf or /etc/mysql/my.cnf. Also check /home/username/my.cnf and /home/username/.mysql/my.cnf

If no luck there you can run

find / -type f -name my.cnf

That will scan you’re entire disk where non priviledged access is allowed (which is fine; it should find it, i’m assuming your distro came with it and you’re able to connect or you wouldn’t be asking this much; but it will tie your disk up)

You can actually find out where your compiled binary is instructed to read options files.

$ mysqld --help --verbose
110923 17:09:29 [Warning] Can't create test file /usr/local/mysql-5.6.2-m5-osx10.6-x86_64/data/laptop1113-2.lower-test
110923 17:09:29 [Warning] Can't create test file /usr/local/mysql-5.6.2-m5-osx10.6-x86_64/data/laptop1113-2.lower-test
110923 17:09:29 [Note] Plugin 'FEDERATED' is disabled.
mysqld  Ver 5.6.2-m5 for osx10.6 on i386 (MySQL Community Server (GPL))
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Starts the MySQL database server.

Usage: mysqld [OPTIONS]

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf 
The following groups are read: mysqld server mysqld-5.6
..

So for me it’s /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf.

Check the MySQL documentation about the precedence of reading configuration files and their location.

On Unix, Linux and Mac OS X, MySQL programs read startup options from the following files, in the specified order (top items are used first).

File Name               Purpose
/etc/my.cnf             Global options
/etc/mysql/my.cnf       Global options (as of MySQL 5.1.15)
SYSCONFDIR/my.cnf       Global options (SYSCONFDIR = etc by default)
$MYSQL_HOME/my.cnf      Server-specific options
defaults-extra-file     The file specified with --defaults-extra-file=path, if any
~/.my.cnf               User-specific options

Depending on your Linux distribution your MySQL server may already be configured with a minimum configuration file and is ready to run, otherwise you may need to create a configuration file before the server can be activated. See Linux Home Server HOWTO – MySQL Server for details. You will find the predefined configurations in:

/usr/share/doc/mysql-server-?.??.??

Leave a Reply

Your email address will not be published.