gtid主从搭建

1.安装 mysql5.7

传送门

2 MySQL主从复制-GTID

1. GTID概念

全局事务标识:global transaction identifiers。

GTID与事务一一对应,并且全局唯一ID。

一个GTID在一个服务器上只执行一次。

MySQL-5.6.5开始支持GTID。

GTID组成:

GTID = server_uuid:transaction_id

2. 配置GTID

配置主从my.cnf

1、主my.cnf:

[root@www ~]# cat /etc/my.cnf

[client]

port      = 3306

socket     = /tmp/mysql.sock

 

[mysql]

no-auto-rehash

 

[mysqld]

user = mysql

basedir = /usr/local/mysql

datadir = /data/mysql/data

port = 3306

socket = /tmp/mysql.sock

log-error = error.log

slow_query_log_file = slow.log

character-set-server = utf8

open_files_limit = 65535

max_connections = 100

max_connect_errors = 100000

lower_case_table_names =1

 

server_id=1

gtid_mode=on

enforce_gtid_consistency=on

\#binlog

log_bin=master-binlog

log-slave-updates=1

binlog_format=row

 

\#relay log

skip-slave-start=1

主服务器上创建复制账户

[root@www tmp]# mysql -uroot -ptest 

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.32-log MySQL Community Server (GPL)

 

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> grant replication slave on *.* to 'repl'@'192.168.137.%' identified by '123456';

Query OK, 0 rows affected, 1 warning (1.82 sec)

在主服务器上备份全库

[root@www ~]# mysqldump -uroot -ptest --set-gtid-purged=OFF --master-data=2 --single-transaction -A > /tmp/mysqlbak_`date +%Y%m%d`.sql


从库上安装mysql(同上安装,传送门

导入mysql主备份的mysql到从服务器上 可以使用scp命令

[root@test ~]# mysql -uroot -ptest

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 5

Server version: 5.7.32 MySQL Communit
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值