MySQL5.7 - based GTID copy from the master copy mode is set up

surroundings:

MySQL5.7.24 version of
CentOS release 6.5


note:

MySQL5.7 Slave version can not open binlog, you can save this part of the disk I / O consumption, and MySQL5.6 version must be turned binlog, because GTID information needs in the binlog stores (log_slave_updates), open only to use GTID the binlog Features. MySQL5.7 version information recorded GITD (mysql.gtid_executed) by GTID system tables, each transaction commits, the message is inserted into the table GTID


Master配置:
[root@master ~]# cat /etc/my.cnf
server_id=1
gtid_mode=on
enforce_gtid_consistency=on
log_bin=/var/lib/mysql/binlog
binlog_format=row
character_set_server=utf8

[root@master ~]# service mysqld restart


Slave configuration:

[the root Slave ~ @] CAT # /etc/my.cnf
the server_id = 2
gtid_mode = ON
enforce_gtid_consistency = ON
binlog_format = Row
relay_log = / var / lib / MySQL / relaylog
replicate_do_db = edusoho_e
the character_set_server UTF8 =

[the root @ Slave ~] #-Service restart mysqld

Master:
view the current binlog situation:
MySQL> Show Master Status;
+ ------------------ + ---------- + ---- ------------------ + ---------- + ------------------- +
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+ ------------------ + ---------- + -------- + ------------------ + ------------------- + ------
| MySQL-bin .000001 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

授权复制连接用户:
mysql> grant replication slave on *.*to repliter@'192.168.32.2' identified by PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9';
Query OK, 0 rows affected, 2 warnings (0.00 sec)

mysql> show warnings;
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                               |
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1287 | 'IDENTIFIED BY PASSWORD' is deprecated and will be removed in a future release. Please use IDENTIFIED WITH <plugin> AS <hash> instead |
| Warning | 1287 | Using GRANT for creating new user is deprecated and will be removed in future release. Create new user with CREATE USER statement.    |
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

创建statistic库:
mysql> create database statistic;
Query OK, 1 row affected (0.01 sec)

创建statistic.t1表:
CREATE TABLE `statistic`.`t1` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`xname` VARCHAR(20) NOT NULL DEFAULT '',
`address` CHAR(20) NOT NULL DEFAULT '',
`sex` TINYINT(1) NOT NULL DEFAULT '1',
`hobby` VARCHAR(30) NOT NULL DEFAULT '',
`age` TINYINT(2) DEFAULT '18',
PRIMARY KEY (`id`),
KEY `idx_name` (`xname`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;

创建edusoho_e库:
mysql> create database edusoho_e;
Query OK, 1 row affected (0.01 sec)

创建edusoho_e.t1表:
CREATE TABLE `edusoho_e`.`t1` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`xname` VARCHAR(20) NOT NULL DEFAULT '',
`address` CHAR(20) NOT NULL DEFAULT '',
`sex` TINYINT(1) NOT NULL DEFAULT '1',
`hobby` VARCHAR(30) NOT NULL DEFAULT '',
`age` TINYINT(2) DEFAULT '18',
PRIMARY KEY (`id`),
KEY `idx_name` (`xname`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;

INSERT INTO `statistic`.`t1` (`xname`, `address`, `hobby`) VALUES ('statistic', '北京', '游戏');
INSERT INTO `edusoho_e`.`t1` (`xname`, `address`, `hobby`) VALUES ('edusoho_e', '上海', '开发');

查看当前binlog情况:
mysql> show master status;
+------------------+----------+--------------+------------------+------------------------------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                        |
+ ------------------ + ---------- + -------------- + ---- ----------------------------------- -------------- + + -------
| MySQL-bin.000001 | 2443 | | | c13c1b45-2741-11e9-abb0-000c29b85ea6: 1-7 |
+ ---------------- - + ---------- + -------------- + ------------------ + - + ----------------------------------------
1 Row in the SET (0.00 sec)

ready copy data:
[root @ Master ~] # mysqldump -p-uroot--B edusoho_e> `DATE +% F`.sql (warning of what information, consult the help of their own)
the Enter password:
warning: a partial dump from Server a that has The default by the include Will GTIDs GTIDs of All Transactions, that changed the even Those Parts of The Database summary suppressed. Not the If you do want to Restore GTIDs, Pass the --set-gtid-Purged = OFF. To make a complete dump, pass --all-databases --triggers --routines --even

Slave导入复制数据:
[root@slave ~]# mysql -uroot -p < 2019-05-29.sql
Enter password:

Slave开始数据复制:
mysql> change master to master_auto_position=1,master_host='192.168.32.3',master_port=3306;
Query OK, 0 rows affected (0.04 sec)

mysql> start slave user='repliter' password='123456';   (会滚动 relay log 日志文件)
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Retrieved_Gtid_Set:
Executed_Gtid_Set: c13c1b45-2741-11e9-abb0-000c29b85ea6:1-7
Auto_Position: 1


至此,MySQL5.7 基于GTID模式的主从复制搭建完毕。如果,你是MySQL5.6的环境,那么请参考 MySQL5.6 基于GTID模式的主从复制搭建,当然了,还有一些常见复制问题的介绍,需要对你有所帮助。


Guess you like

Origin blog.51cto.com/20131104/2401897