HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How to set datadir to different values based on the hostname in my.cnf?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
datadirthecnfdifferenthostnamebasedhowvaluesset

Problem

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.

Solution

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

Code Snippets

[mysqld]
datadir=/mysql_data
cd /
ln -s /var/lib/mysql mysql_data
chown mysql:mysql /mysql_data

Context

StackExchange Database Administrators Q#14993, answer score: 2

Revisions (0)

No revisions yet.