分配一下角色
172.16.2.5 为主
172.16.2.3 为辅
切记关闭selinux 要不有你蛋疼的时候
vi /etc/my.cnf 添加一下内容(主)
innodb_file_per_table = ON
server-id
= 1
log-bin = master-bin
binlog-
format
=ROW
log-slave-updates=
true
gtid-mode=on
enforce-gtid-consistency=
true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync
-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
report-port=3306
report-host=172.16.2.5
启动mysql
mysql> show global variables like '%gtid%';
+--------------------------+------------------------------------------+
| Variable_name | Value |
+--------------------------+------------------------------------------+
| enforce_gtid_consistency | ON 俩个都为on 说明gtid
已经启用 |
| gtid_executed | 26cb56f0-0fce-11e3-a9ec-eef1eccc36ac:1-3 |
| gtid_mode | ON |
| gtid_owned | |
| gtid_purged | |
+--------------------------+------------------------------------------+
5 rows in set (0.00 sec)
授予从上的用户与密码
GRANT REPLICATION SLAVE ON *.* TO 'kyo'@'172.16.%.%' IDENTIFIED BY 'kyo';
flush privileges;
接下来在slave上设置
vi /etc/my.cnf
innodb_file_per_table = ON
binlog-format=ROW
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
report-port=3306
report-host=172.16.2.3
这里的server_id要为2
启动mysql
mysql> change master to master_host='172.16.2.5',
master_user='kyo',master_password='kyo',master_auto_position=1; 进行复制
mysql> start slave;
mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.2.5
Master_User: kyo
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000001 主的二进制文件
Read_Master_Log_Pos: 524
Relay_Log_File: localhost-relay-bin.000002
Relay_Log_Pos: 736
Relay_Master_Log_File: master-bin.000001
Slave_IO_Running: Yes 复制的进程全部为yes
Slave_SQL_Running: Yes
测试
在主的mysql上面添加数据库 再从的上面查看是否同步
mysql> create database qilei; 主
mysql> show databases; 从
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| qilei |
| test |
+--------------------+
ok 有了 大功告成