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:

mysql> SHOW MASTER STATUS;
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:

MYSQL_CONF_ADDITIONS="
# ----------------------------------------
# Allow connections from all addresses
bind-address = 0.0.0.0
# ------------------------------
"

perl -i -p -e "print '${MYSQL_CONF_ADDITIONS}',$_='' if \$_ =~ /bind-address.*127.0.0.1/)" /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