Take the 2-minute tour ×
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. It's 100% free, no registration required.

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
1  
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

1 Answer 1

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:

[mysqld]
datadir=/mysql_data

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

 
discard

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.