1.介绍
复制2台以上节点,通过binlog实现最终“同步”关系
2.复制前提(搭建过程)
2个以上MySQL实例
源端开启binlog日志 , 创建复制用户。
mysql> select @@log_bin;
mysql> select @@log_bin_basename;
mysql> create user repl@'10.0.0.%' identified with mysql_native_password by '123';
mysql> grant replication slave on . to repl@'10.0.0.%';server_id server_uuid不同
mysql> select @@server_id;
mysql> select @@server_uuid;
+--------------------------------------+
| @@server_uuid |
+--------------------------------------+
| 1cc19357-f1b9-11ea-b9cc-000c29914382 |
+--------------------------------------+
1 row in set (0.00 sec)
mysql> set global server_id=8;
- 版本一般一致
- 从库的数据同步(mysqldump xtrabackup clone plugin).
远程克隆
4.2.0 各个节点加载插件
INSTALL PLUGIN clone SONAME 'mysql_clone.so';
或
[mysqld]
plugin-load-add=mysql_clone.so
clone=FORCE_PLUS_PERMANENT
SELECT PLUGIN_NAME, PLUGIN_STATUS
FROM INFORMATION_SCHEMA.PLUGINS
WHERE PLUGIN_NAME LIKE 'clone';
4.2.1 创建远程clone用户
捐赠者(source)授权
create user test_s@'%' identified by '123';
grant backup_admin on . to test_s@'%';
接受者(target)授权
create user test_t@'%' identified by '123';
grant clone_admin on . to test_t@'%';
4.2.2 远程clone(目标端)
开始克隆
SET GLOBAL clone_valid_donor_list='10.0.0.51:3306';
mysql -utest_t -p123 -h10.0.0.52 -P3306
CLONE INSTANCE FROM test_s@'10.0.0.51':3306 IDENTIFIED BY '123';
- 告诉从库连接信息,从什么位置开始自动复制 change master to
mysql> select *from performance_schema.clone_status\G
help change master to 可以查看这个模板
CHANGE MASTER TO
MASTER_HOST='10.0.0.51',
MASTER_USER='repl',
MASTER_PASSWORD='123',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000005',
MASTER_LOG_POS=156,
MASTER_CONNECT_RETRY=10;
- 启动专用复制线程 start slave;
mysql> start slave ;
mysql> show slave status \G