First, the environment:
1. Two machines for installing the centos-6.5-x64-bit system:
host1:192.168.2.3
host2:192.168.2.4 (can ping through each other)
2. Install MySQL. Command: Yum Install mysql-*
Second, the configuration:
1. Start MySQL. Command: Service mysqld start
Set the root password for MySQL. Command: Mysqladmin–u root password Enter the password you want to set.
2. Create Database Test1 and table test1.
Create database test1;
Use test1;
Create table test1 (id int (5), name varchar (10));
3. Configure the mysql configuration file:/etc/my.cnf. The configuration content is as follows:
Host1:
[Mysqld]
Server-id=1
Log-bin=bin-log
Binlog-ignore-db=mysql,test,infromation_schema
Binlog-do-db=test1
master-host=192.168.2.4
master-port=3306
Master-user=root
master-password=111
master-retry-count=999
Master-connect-retry=60
Host2:
[Mysqld]
server-id=2
Log-bin=bin-log
Binlog-ignore-db=mysql,test,infromation_schema
Binlog-do-db=test1
master-host=192.168.2.3
master-port=3306
Master-user=root
master-password=110
master-retry-count=999
Master-connect-retry=60
4. restart mysql. Command:service mysqld Restart
1. If the service cannot be started, carefully check that the configuration file is incorrectly written and that the firewall is turned off after checking it correctly. Command: Service iptables stop (chkconfig iptables off).
2.host1 uses Mysql–h host2. Ip–u root–p login Host2 MySQL to see if the success
3.host2 uses Mysql–h host1. Ip–u root–p login host1 MySQL to see if the success
The successful description of the MySQL service and access on the dual machine is normal.
5. Configure authorization.
Host1:mysql>grant replivation Slave on * * to ' root ' @ ' 192.168.2.4 ' identified ' host1 ' root password in MySQL ';
Host2:mysql>grant replivation Slave on * * to ' root ' @ ' 192.168.2.3 ' identified ' host2 ' root password in MySQL ';
6.host1 , Host2 log in to this machine separately MySQL . mysql–u root–p Enter the password.
To view the master and slave states:
Command: Show Master status\g;
Show slave status\g;
Host1:
Host2:
As shown in the results, slave_io_running and slave_sqlrunning are yes to indicate a successful configuration.
If Slave_io_running:no appears; Last_io_error:got fatal Error 1236 from master when reading data from binary log: ' Client requested Master to start REPL Ication from impossible position '
Error, it is because of a configuration problem with the host log file.
Workaround: use show Master status\g, view the values of file and position for master, and then use the command settings:
mysql> stop Slave;
mysql> Change Master to master_log_file= ' file value ', master_log_pos=position value;
mysql> start slave;
7. Test:
Test by inserting different data in the Mysql-jhk-test1 table of host1 and Host2 respectively.
The results show that the two machines are mutually hot-backed. Delete Data and table tests (slightly)
Original MySQL Dual computer backup for CentOS