-- 查看配置文件存在位置
show variables like '%data%';

在Linux下叫my.cnf,该文件位于/etc/my.cnf
boo_db为同步的数据库名 server-id=1
log-bin=mysql-bin
#目标数据库
binlog_do_db=boo_db
create user 'slave'@'192.168.5.128' identified by '123456';
GRANT ALL PRIVILEGES ON *.* TO 'slave'@'192.168.5.128'; -- 给全部权限
FLUSH PRIVILEGES;
--修改连接的密码方式:
update mysql.user set plugin='mysql_native_password' where user='slave';
FLUSH PRIVILEGES;
server-id=2 #指定唯一的ID,2至32,必须的,并且不能跟主数据库一样
replicate-do-db=boo_db # 指定要同步的数据库,必须的
replicate-ignore-db=cs_db# 指定不要同步的数据库。
>> mysql -uslave -p123456 -h192.168.1.16
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000222| 1160| rpa-cloud | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.01 sec)
mysql > change master to
> master_host='192.168.1.16',
> master_port=3306,
> master_user='slave',
> master_password='123456',
> master_log_file='mysql-bin.000222',
> master_log_pos=1160;
mysql > start slave;
-- 确定需要同步的主机信息
change master to master_host='192.168.1.16',master_user='slave',master_password='123456',master_port=3306,master_log_file='mysql-bin.000222',master_log_pos=1160;
-- 开启 slave
start slave;
-- 关闭 slave
STOP slave;
-- 查看slave状态
show slave status;
master_host指向主机地址,
master_port指向主机端口
master_user是主库里面添加的只允许从库访问的用户
master_password是密码
mysql > show slave status \G;
查看状态为:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
时 slave 启动成功

The replication receiver thread cannot start because the master has GTID_MODE = ON and this server has GTID_MODE = OFF. 大致意思是 主库开启了 GTID 但是从库没有开启,这里开启从库的GTID就可以了,开启GTID的方法可以参考一般是事务回滚造成的:
解决办法:
mysql> stop slave ;
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1; -- 跳过这个错误
mysql> start slave ;