Skip to main content

Posts

Showing posts from November, 2016

Master Slave Replication to Automatically Backup Your MySQL Database

We can make backup for some databases by periodically running a kind of dump query, like mysqldump in MySQL. That's the simplest method but it can drain our server resources and it's not suitable for large databases. MySQL comes up with master-slave features that allow you to replicate your database to another location (slave). This mechanism enables MySQL to generate a log file which records any action performed to the database. Then, that action will be run in slave database too. For example, we have two database servers with IP address 192.168.0.1 (Master) and 192.168.0.2 (Slave). 1) Configure my.cnf in master server # Master Settings # locate where the changes record will be stored log-bin = /var/log/mysql/mysql-bin.log # set unique ID for master database in master-slave network (up to you) server-id = 111 innodb_flush_log_at_trx_commit = 1 sync_binlog = 1 # select database which will be replicated # by default system will log all databases binlog-do-db =