It is possible to use environment variables in an Apache .conf
file, but what about MySQL, is there a way to use them in the MySQL configuration file (my.ini
/my.cfg
)?
The closest thing I could find was a MySQL man-page that mentions some variables but does not indicate how to use them or if they are even system variables or internal variables.
In my case, I need a way to specify that the logs should be stored in a subdirectory of the system temp-directory, but cannot figure out how to indicate that. For example:
log-error="${temp}/MySQL_Logs/error.log"
innodb_log_group_home_dir="%temp%/PS_Logs/Logs/MySQL/"
?
You can't do it in the config file, but you can modify the start command to set them that way.
eg:
Set LOG_DIR="your log dir" in the console.
Then modify the start script to include the log-error option.
Probably not the most elegant solution but perhaps the static configuration file can be replaced by dynamic content:
You could put a FIFO at the log file path. Before you start MySQL you would have to start a mini daemon which writes to that FIFO in an endless loop. Race conditions should not be a problem here.
The daemon would write two blocks of data to the FIFO, first a dummy line like # environment aware config file following in order to open the FIFO. As soon as this first write returns it would get the PID of the reading process (e.g. via fuser), get the variables which occur in the file from /proc/${PID}/environ, create commands for e.g. sed to replace the references and write the sed output to the FIFO.