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.

| 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

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
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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