1. install mysql on master and slave host
master host: 192.168.10.98
slave host: 192.168.10.96
-- create same database and table on master host and slave host.
create database test_db;
use test_db;
create table test_table (id int(10), account char(10), passwd char(10));
2. configure master host
-- edit my.cnf
## Replication
server-id = 1001
log-bin = mysql-bin
You may set server-id from 1 to 2^23 -1 freely
-- grant slave host
grant replication slave on *.* to 'slave96'@'192.168.10.96' identified by 'slave9696';
--flush database
FLUSH TABLES WITH READ lOCK;
-- show master status
sudo mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 1837 | | |
+------------------+----------+--------------+------------------+
Please remember the file and position value
-- unlock
UNLOCK TABLES;
3. configure slave host
-- edit my.cnf
## Replication
server-id = 1002
log-bin = mysql-bin
-- change the master
change master to
master_host=’192.168.10.98’,
master_user=’slave96’,
master_password=’slave9696’,
master_log_file=’mysql-bin.000001’,
master_log_pos=1837;
--start slave
start slave
--check slave statuss
show slave status;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.10.98
Master_User: slave96
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 2167
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 2144
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
----------
In the show above, the Slave_IO_Running and Slave_SQL_Running must be YES.
Till now, you have completed the configure for master-slave. Please try this functionality.
Insert one record on master host
INSERT INTO test_table VALUES(100,'Jone', 'Jone100');
You may check the slave host. There must be one same record on slave host.
No comments:
Post a Comment