-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure
More file actions
190 lines (135 loc) · 5.13 KB
/
configure
File metadata and controls
190 lines (135 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
声明:关闭防火墙
cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
IP:
master 192.168.3.105
slave 192.168.3.106
master端:
mysql -uroot -p #可以接-e然后接命令
create user zhangsan;
grant replication slave on *.* to 'zhangsan'@'192.168.3.106'identified by '123456';
flush privileges;
vim /etc/my.cnf
[mmysqld]
....
....
server-id=1
gtid-mode = on #开启GTID需要
enforce-gtid-consistency = true #开启GTID需要
log-bin-index=master-bin.index
#binlog
master-info-repository = TABLE #Slave配置需要
relay-log-info_repository = TABLE #Slave配置需要
log_bin=master-binlog
binlog-format =ROW #Slave配置需要
log-slave-updates = ON
binlog-checksum = CRC32
master-verify-checksum = 1
....
.....
service mysqld restart
mysql -uroot -p #登录数据库
mysql> show variables like '%gtid%'; #查看主库与从库的GTID是否开启
mysql> show variables like '%gtid_next%';
mysql> show variables like '%uuid%'; #查看服务器server_uuid
slave端:(脚本安装好以后,除自带的选项外新添加以下选项)
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
port=3306
#binlog
log-slave-updates = ON
log-bin=slave-binlog
master-info-repository = TABLE #Slave配置需要
relay-log-info_repository = TABLE #Slave配置需要
binlog-format =ROW #Slave配置需要
#GTID
server_id=106
gtid-mode = on #开启GTID需要
enforce-gtid-consistency = true #开启GTID需要
binlog-checksum = CRC32
master-verify-checksum = 1
skip_slave_start=1
service mysqld restart
mysql> change master to
master_host='192.168.3.105', #master端地址
master_port=3306,
master_user='zhangsan', #master端授权的用户
master_password='123456, #master端授权用户的密码
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: 192.168.3.105
Master_User: zhangsan
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-binlog.000001
Read_Master_Log_Pos: 154
Relay_Log_File: localhost-relay-bin.000002
Relay_Log_Pos: 375
Relay_Master_Log_File: master-binlog.000001
Slave_IO_Running: Yes #确保IO线程是Yes状态
Slave_SQL_Running: Yes #确保SQL线程是Yes状态
....
....
master端测试:
mysql -uroot -p #登录数据库
mysql> show databases;
mysql> show master status;
+----------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------------+----------+--------------+------------------+-------------------+
| master-binlog.000001 | 154 | | | |
+----------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql> create database opop;
mysql> use opop;
mysql> create table a1(id int,name char(20),sex char(10));
mysql> desc a1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | char(20) | YES | | NULL | |
| sex | char(10) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.04 sec
mysql> show master status;
+----------------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------------+----------+--------------+------------------+------------------------------------------+
| master-binlog.000001 | 502 | | | 889cd7e6-bbb7-11e8-9461-000c29f304ff:1-2 |
+----------------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
slave端测试:
mysql -uroot -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| opop |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.04 sec)
mysql> use opop;
mysql> show tables;
+----------------+
| Tables_in_opop |
+----------------+
| a1 |
+----------------+
1 row in set (0.00 sec)
mysql> desc a1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | char(20) | YES | | NULL | |
| sex | char(10) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)