Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to set datadir to different values based on the hostname in my.cnf? I want to use the same my.cnf file on a Linux machine and a Mac OS X machine where the datadir should have different values.

share|improve this question
One possibility is to modify the DB startup script on each machine to pass the --datadir=/your/data/path to mysqld. That way no modification is needed to your my.cnf file. A second option would be to use the "!include /etc/mylocal.cnf" directive in your global my.cnf & then have /etc/mylocal.cnf contain the specific datadir= directive. – Phil Mar 14 '12 at 15:14
up vote 2 down vote accepted

A simple solution for that would be to keep the my.cnf file identical, and use symlinks on your machine sto point to whatever directory you want the data to be in. For example, assuming you my.cnf contains this:


On you linux host, you would:

cd /
ln -s /var/lib/mysql mysql_data

Add permissions to this folder for mysql user:

chown mysql:mysql /mysql_data
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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