| mysql-bin.000007 | 120 | students | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
2 在原主上添加:
vim /etc/my.cnf
添加:
replicate-do-db = xxx 要接收的库
# /etc/init.d/mysql restart
Shutting down MySQL... SUCCESS!
Starting MySQL..... SUCCESS!
mysql -uroot -p
mysql> change master to master_host='192.168.1.166',master_user='hm100',master_password='abc-123',master_log_file='mysql-bin.000007', master_log_pos=120;
mysql> start slave;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.166
Master_User: hm100
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 120
Relay_Log_File: localhost-relay-bin.000004
Relay_Log_Pos: 283
Relay_Master_Log_File: mysql-bin.000007
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: shudents
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
......
3 测试:
在原从上添加数据:
mysql> use students;
mysql> select * from users;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
+----+------+
mysql> use students;
mysql> insert into users values (7,"g");
mysql> select * from users;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
| 7 | g |
+----+------+
看原主
mysql> select * from users;
+----+------+
| id | name |
+----+------+
| 1 | a |
| 2 | b |
| 3 | c |
| 7 | g |
+----+------+
到此就实现了主主。
注意:
在mysql5.6之后不用指定以下,不然会出现报错: