MySQL 5.6利用GTIDs构建主从数据库(一)

2015-07-20 12:04:31 · 作者: · 浏览: 0

【概念】什么是GTIDS


(Global Transactions Identifier)是MySQL5.6.5新加入的一项新特性。


【关于GTID】GTID由source_id和transaction_id两部门组成。



[root@t-db01 mysql]# cat auto.cnf
[auto]
server-uuid=268e23d1-2216-11e5-abcc-000c296ecd05


mysql> show global variables like 'gtid_executed';
+---------------+-----------------------------------------------------+
| Variable_name | Value? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |
+---------------+-----------------------------------------------------+
| gtid_executed? | 268e23d1-2216-11e5-abcc-000c296ecd05:1-28? ? |
+---------------+-----------------------------------------------------+


【构建主从数据库


环境说明:


1、主库参数的设置


server_id = 1
binlog-format=ROW? #建议使用ROW格式
log-bin=mysql-bin? ? ? #打开binlog
report-port=3306
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=true
replicate_do_db=JOHN_DB


2、从库参数的设置


server_id = 2
log-bin=mysql-bin
report-port=3306
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=true
replicate_do_db=JOHN_DB
skip-slave-start? ? #启动的时候自动打开复制


检查gtid是否启用:show global variables like ‘%gtid%’;



3、在主库上面用户的创建


grant replication slave on JOHN_DB.* to 'repl'@'192.168.47.186' identified by 'repl';


4、进行从库数据的初始化


操作的步骤跟5.5的步骤一样,这边就偷懒不再重复了;


5、配置从库连接主库


从库连接主库:
change master to master_host='192.168.47.169', master_user='repl',master_password='repl',master_auto_position=1;


启动从库:
start slave;


检查状态:
show slave status\G;



mysql> show slave status\G;
*************************** 1. row ***************************
? ? ? ? ? ? ? Slave_IO_State: Waiting for master to send event
? ? ? ? ? ? ? ? ? Master_Host: 192.168.47.169
? ? ? ? ? ? ? ? ? Master_User: repl
? ? ? ? ? ? ? ? ? Master_Port: 3306
? ? ? ? ? ? ? ? Connect_Retry: 60
? ? ? ? ? ? ? Master_Log_File: mysql-bin.000009
? ? ? ? ? Read_Master_Log_Pos: 485
? ? ? ? ? ? ? Relay_Log_File: t-db02-relay-bin.000012
? ? ? ? ? ? ? ? Relay_Log_Pos: 695
? ? ? ? Relay_Master_Log_File: mysql-bin.000009
? ? ? ? ? ? Slave_IO_Running: Yes
? ? ? ? ? ? Slave_SQL_Running: Yes
? ? ? ? ? ? ? Replicate_Do_DB: JOHN_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: 485
? ? ? ? ? ? ? Relay_Log_Space: 1150
? ? ? ? ? ? ? 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: 31
? ? ? ? ? ? ? ? ? Master_UUID: 268e23d1-2216-11e5-abcc-000c296ecd05
? ? ? ? ? ? Master_Info_File: /data/mysql/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: 268e23d1-2216-11e5-abcc-000c296ecd05:1-29
? ? ? ? ? ? Executed_Gtid_Set: 268e23d1-2216-11e5-abcc-000c296ecd05:1-29
? ? ? ? ? ? ? ? Auto_Position: 1
1 row in set (0.02 sec)


ERROR:
No que