How To Set Up Master And Slave MYSQL
In this tutorial I am going to teach you one of the most important MySQL techniques that you must use in your software development. Today huge amount of business use MySQL as their data base. Imagine if their database corrupted what would be happen ?, If your server crashed what word you do ? So we must use database backup technique to overcome those issues.
Now I am going to explain you one of the best solution for above issue is master slave replication for MySQL . That’s mean you have to copies of same database one as master and other as slave. In this scenario you always dealing with master for your needs but you have up to date backup as slave.
I am here going to used ubuntu and MySQL 5.5
How to set the master
If you have brand new server update APT cash and update server
sudo apt-GET UPDATE; sudo apt-GET install mysql-server
sudo vim /etc/mysql/my.cnf
bind_address = 127.0.0.1
bind_address = 0.0.0.0
Also uncomment following lines
server-id = 1 log_bin = /var/log/mysql/mysql-bin.log
Second line we are removing current backup mechanism. That is LOG
After you done this restart the mysql
sudo service mysql restart
mysql -u root -p
GRANT REPLICATION SLAVE ON *.* TO ‘replication’@’192.168.2.2 IDENTIFIED BY ‘password’;
At first we need to clear APT cash and installed MySQL
sudo apt-GET UPDATE; sudo apt-GET install mysql-server
After that open my.cnf file
sudo vim /etc/mysql/my.cnf
server-id = 2
sudo service mysql restart
mysql -u root -p
CHANGE MASTER TO MASTER_HOST=’192.168.2.2′, MASTER_USER=’replication’, MASTER_PASSWORD=’password’;
SLAVE START;
SHOW SLAVE STATUS;
Then create database on master and after that give following quarry to slave
SHOW DATABASES;
Download Link
0 Commentaires