后续继续更新
前言:利用mysql-5.6版本的gtid配置主从复制.
环境描述:
1.两个MySQL实例
a.单机多实例或双机单实例
b.图解
第一章:先觉条件
1.1 主库和从库需要开启binlog
1.2 主库和从库的server-id不一致
1.3 需要主从复制的用户
第二章:修改配置
A.主库的修改
2.1 开启binlog
log_bin=mysql-bin
2.2 修改server-id
server-id=1
2.3创建主从复制用户
grant replication slave on *.* rep@'192.168.122.%' indentified by '123456';
2.4 开启从库的binlog更新
log-slave-updates
B.从库修改
重复2.1 2.2 2.4 步骤,因为从库也需要打开binlog日志,打开gtid功能,binlog更新.
2.5 从库配置
a. show slave status;
Empty set (0.00 sec)
否则reset slave all;
b.指向主库
change master to master_host='192.168.122.218',master_user='rep',master_password='Ritchie',master_auto_position=1;
c. 开启做为从库
start slave;
d. 检查show slave status\G;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.122.218
Master_User: rep
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 151
Relay_Log_File: nagios2-relay-bin.000002
Relay_Log_Pos: 361
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
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
Exec_Master_Log_Pos: 151
Relay_Log_Space: 567
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: f58cc4ef-19d6-11e8-8605-5254006de4c1
Master_Info_File: /usr/local/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 1
1 row in set (0.00 sec)
ERROR:
No query specified
如果看见这两个yes证明就ok了.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
也许不成功:但可以查看这两个参数
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
例如:这里就说明主库连接超时.这就要检查了.
Last_IO_Errno: 2003
Last_IO_Error: error connecting to master 'rep@192.168.122.218:3306' - retry-time: 60 retries: 3
2.6 禁止自动删除relay日志
a,查看:relay_log_recovery | OFF |
mysql> show global variables like '%relay%';
+---------------------------+----------------+
| Variable_name | Value |
+---------------------------+----------------+
| max_relay_log_size | 0 |
| relay_log | |
| relay_log_basename | |
| relay_log_index | |
| relay_log_info_file | relay-log.info |
| relay_log_info_repository | FILE |
| relay_log_purge | ON |
| relay_log_recovery | OFF |
| relay_log_space_limit | 0 |
| sync_relay_log | 10000 |
| sync_relay_log_info | 10000 |
+---------------------------+----------------+
11 rows in set (0.00 sec)
b. 在线修改
mysql> set global relay_log_purge=0;
c. 修改配置文件
[mysqld]
relay_log_purge=0