Mysql主从复制架构实战

[root@Mysql-master ~]# vim /etc/my.cnf

log-bin=mysql-bin

server-id = 1  #slave端server-id值改成2

mysql> grant replication slave on *.* to 'xiaoyu'@'192.168.2.139' identified by '123.com';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

 mysql> slave stop;

1Query OK, 0 rows affected (0.55 sec)

mysql> change master to
-> master_host='192.168.2.137'
-> master_user='xiaoyu',
-> master_password='123.com'
-> master_log_file='mysql-bin.000005',
-> master_log_pos=107;
HQuery OK, 0 rows affected (1.13 sec)

mysql> slave start;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

在Master端上创建一个名为“testDB”测试的数据库并在里面创建test01表,在slave端检查一下是否同步过来!

mysql> create database testDB;
Query OK, 1 row affected (0.00 sec)

mysql> use testDB;
Database changed
mysql> create table test01 (id varchar(20),name varchar(30));
Query OK, 0 rows affected (0.21 sec)

mysql> show tables;

 

posted @ 2017-11-25 13:34  Mr&Yu  阅读(208)  评论(0编辑  收藏  举报