mysql replication

I am currently working on a script to automate the process of setting up mysql database replication. I followed various tutorials but I always got stuck here:

Empty set (0.00 sec)

Endless googling was no help (which is why I am blogging this). Eventually I realized that /etc/mysql/my.cnf was context sensitive, meaning that I couldn't just append the replication configuration to the end of the file. This meant I needed to insert the configuration into the appropriate place in the file. This meant inserting multiple lines of text into the middle of the file. Eventually I came up with the following:

(Update) I used to do this with ruby, but I switched to perl since ruby isn't installed by default:

# ----------------------------------------
# Allow connections from all addresses
bind-address =
# ------------------------------

perl -i -p -e "print '${MYSQL_CONF_ADDITIONS}',$_='' if \$_ =~ /bind-address.*" /etc/mysql/my.cnf

Hopefully this will be useful to somebody, someday, somewhere.

1 Response to mysql replication

  1. this will be thoroughly used, "abused" and instituted in the future CHITS installation! -- darth_ali :D

Post a Comment