How To Set Up Master And Slave MYSQL
Submitted by thusitcp on Tuesday, October 28, 2014 - 11:50.
Language
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
Then open open up the my.cnf file which contained database configuration
Then change the following line
To
Upto now what we have done is set the mysql listning all the IP addresses
Also uncomment following lines
First line we are removing server id
Second line we are removing current backup mechanism. That is LOG
After you done this restart the mysql
Then log into database as root with password
At thefinal step we need to add user account for the slave. This user account help slave login to master and do operations
Setting up slave
At first we need to clear APT cash and installed MySQL
During the installation you need to provide password.
After that open my.cnf file
Uncomment following line
Save the file and you need to restart mysql server
Then log in to with your password
Use following query to set up master slave relation
After that start the slave
Then you can test the status of slave
Above will prompt “Waiting for master to send event”
Then create database on master and after that give following quarry to slave
SHOW DATABASES;
- 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
- server-id = 1
- log_bin = /var/log/mysql/mysql-bin.log
- sudo service mysql restart
- mysql -u root -p
- GRANT REPLICATION SLAVE ON *.* TO ‘replication’@’192.168.2.2 IDENTIFIED BY ‘password’;
- sudo apt-GET UPDATE; sudo apt-GET install mysql-server
- 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;
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Comments
Add new comment
- Add new comment
- 216 views