MySQL replication allows you have one MySQL machine crash and still have the entire database available and update to date. It works by each MySQL machine acting as the slave to the other, and copying updates to the database in the other machine's binary logs in real time. When used in combination with heartbeat it gives high availability for the database.

To configure replication

  1. Edit /etc/my.cnf or /etc/mysql/my.cnf on both machines, and set:
    • log_bin = /var/lib/mysql/mysql-bin.log
    • server-id = 1 on the primary machine, and server-id = 2 on the backup machine.
    • Comment out "bind-address = 127.0.0.1".
  2. Restart mysqld.
  3. On the primary machine, use mysqldump to dump the "enswitch" database to a file.
  4. On the primary machine, do "show master status;" and note the file and position.
  5. Copy the dump file to the slave. If NFS is configured, you can use that.
  6. On both machines, do:
    • slave stop;
  7. On the backup machine, do:
    • drop database enswitch;
    • create database enswitch;
    • use enswitch;
    • \. <dump file>
    • show master status;
  8. On both machines, do:
    • grant super, replication client, replication slave, reload on *.* to replicate@'%' identified by '<password>';
    • change master to master_host='<IP address of other machine>', master_user='replicate', master_password='<password>', master_log_file='<master log file on other machine>', master_log_pos=<master log position on other machine>;
    • slave start;
    • show slave status;