mysql-5.6--gtid主从配置
在主库上导出数据
mysqldump -uroot -p --all-databases --single-transaction --triggers --routines --events > master-20190508-1.sql
查看文件内容
head -30 master-20190508-1.sql
--
-- Host: localhost Database:
-- ------------------------------------------------------
-- Server version 5.6.12-log
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
SET @MYSQLDUMP_TEMP_LOG_BIN = @@SESSION.SQL_LOG_BIN;
SET @@SESSION.SQL_LOG_BIN= 0;
--
-- GTID state at the beginning of the backup
--
SET @@GLOBAL.GTID_PURGED='2969720f-96e7-11e7-b033-92156d0584a5:1-25988615';
--
-- Current Database: `big_screen_data`
--
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `big_screen_data` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
导出的sql文件会记录GTID的值
SET @@GLOBAL.GTID_PURGED='2969720f-96e7-11e7-b033-92156d0584a5:1-25988615';
在主库上创建用来做同步的账户
CREATE USER 'repl'@'192.168.0.2' IDENTIFIED BY '密码'; #192.168.0.2 为从库的地址
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.0.2'; #添加权限
FLUSH PRIVILEGES; #刷新权限,立马生效
拷贝导出的sql文件到从库本地
重置从库的GTID值
reset master;
在从库上导入数据
source /root/master-20190508-1.sql;
导入完成后在从库开始配置
change master to master_host = '192.168.0.1', master_port = 3306 ,master_user = 'repl', master_password='密码',master_auto_position=1;
启动同步进程
start slave;
查看状态
show slave status\G